Am Samstag, den 29.11.2014, 20:24 -0800 schrieb Jordan W: > 2. Object extension: I believe that OCaml immediate objects are fairly > under-appreciated, I wouldn't say so. As I'm not a big fan of inheritance immediate objects are the simpler and more expressive of dealing with objects. > and most people could find useful applications for them (at least) in > the form of row polymorphic records. However, there are several > features that would make them even more powerful. The feature I long > for the most is object extension (on immediate objects). OCaml has > support for extending objects (inheritance), but only via classes. Basically, the availability of inheritance is the big difference between classes and functions returning immediate objects. As of now, you need to define classes if you want extensibility. But inheritance is of course more than that; in particular you can also override existing methods (and that's what I in particular don't like about it, as this leads to hard to understand program flows). What could in deed be useful is a more light-weight construction that layers objects, i.e. you define a new object around an existing one: Something like let new_object (old_object : t) = object (* Define some new methods: *) method foo = ... (* And make all methods of old_object also available *) method _ = old_object # _ (* This notation shall mean that we define all methods x as method x = old_object # x and do this for all methods from t that haven't been defined otherwise *) end This is very different from inheritance, because you have an outer object and an inner, and the interface of the inner object is respected (i.e. if another method of old_object calls foo, it is sure it calls the version of foo in old_object, and not the new definition in new_object). And this layering or wrapping construction is of course compatible with immediate objects. Gerd -- ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de My OCaml site: http://www.camlcity.org Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------