> let myFunction delta {} = x + y + delta > let myFunction delta o = o#(x + y + delta) Calling methods is an effectful operation, so you need to specify when (and how many time) the methods are called for those local-open or pattern-matching syntax. It is intuitively clear to me that the semantics of let {< x; y; ... }> = obj in body should be equivalent to let x = obj#x and y = obj#y in body (notice that the other methods of the same object are not forced) I don't think there is a reasonable semantics for obj#(x + y): - you really don't want to reason on the free variables that are inside the parentheses - you may not know what the type of `obj` is yet (let foo obj = obj#(x + y)), so you don't know what its methods are. On Mon, Dec 8, 2014 at 10:34 AM, Goswin von Brederlow wrote: > On Sun, Nov 30, 2014 at 02:45:19PM +0100, Philippe Wang wrote: > > Hi, > > > > Just some quick thoughts about 3.: it's not object matching! It looks > > a little like it, but it's not at all, in the sense that it's not at > > all like the rest of OCaml's pattern matching stuff. > > I would somewhat find it useful, but probably too misleading and > > confusing to encourage having this feature. > > > > I was going to say it's not shorter or easier to write it this way, but > actually > > let myFunction delta {} = x + y + delta > > is a little shorter than something like > > let myFunction delta (o: ) = o#x + o#y + delta > > but, still, I don't really see something good in there. > > > > Cheers, > > Philippe Wang > > How about this syntax (similar to local open of modules): > > let myFunction delta o = o#(x + y + delta) > > MfG > Goswin > > > > On Sun, Nov 30, 2014 at 5:24 AM, Jordan W wrote: > > > 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 = {} > > > > > > 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 + delta > > > > > > let myFunction delta o = match o with > > > {} -> 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 > > > > -- > > Caml-list mailing list. Subscription management and archives: > > https://sympa.inria.fr/sympa/arc/caml-list > > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > > Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >