Hello,

May be i misunderstand something with point n°1.
Otherwise it seems pretty easy to me :

    let x = 10
    let y = 20
    let o =
    begin
      object
        method x = x
        method y = y
      end
    end



Le 30/11/2014 à 05:24:32, Jordan W <jordojw@gmail.com> à écrit :
Hello,

I've encountered several situations where I would have benefited from the following features. I am curious what some of the OCaml core developers think about them.

1. Object punning:
I understand that object punning on "functional updates" to objects was recently added to trunk. This is a nice consistency, but I haven't found a way to perform object punning on methods or values for object *expressions*.

    let x = 10
    let y = 20
    let o = object
      method x
      method y
    end

Which would create an object with two methods x, y that return x and y respectively. It may be easy to apply the same convention to object values.

2. Object extension: I believe that OCaml immediate objects are fairly under-appreciated, 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. I understand that implementing this may complicate dynamic dispatch and/or use of `self`, but perhaps some compromise could be reached - something like a limited form of `inherit`, that is allowed to have different semantics and works on immediate objects (at least in the case when objects are being used as row-polymorphic records).

    let oldObj = object method x = 20 method greet = "hi" end
    let newObj = {<oldObj with method x = 10 >}

This is similar to Andreas Rossberg's Record Extensions in SuccessorML.

New languages are picking up these extensible record features as described in Daan Leijen's paper [Extensible Records With Scoped Labels] and I suspect this feature will be of interest to many others.

3. Object matching.

    let myFunction delta {<x; y; ..>} = x + y + delta

    let myFunction delta o = match o with
        {<x; y; .. >} -> x + y + delta


This may be relatively easy to implement (my reasoning is that I believe it could even be solved at the parsing stage (not that it would be a good idea to do so)).


Thanks for listening. I'm curious if anyone's given thought to implementing these, and eager to hear thoughts/suggestions.

Jordan