caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Object Features
@ 2014-11-30  4:24 Jordan W
  2014-11-30 13:45 ` Philippe Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jordan W @ 2014-11-30  4:24 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 2258 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2786 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [Caml-list] Object Features
@ 2014-11-30 15:53 Damien Guichard
  0 siblings, 0 replies; 10+ messages in thread
From: Damien Guichard @ 2014-11-30 15:53 UTC (permalink / raw)
  To: Caml Mailing List

[-- Attachment #1: Type: text/plain, Size: 2669 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 4372 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-12-26 23:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-30  4:24 [Caml-list] Object Features Jordan W
2014-11-30 13:45 ` Philippe Wang
2014-12-08  9:34   ` Goswin von Brederlow
2014-12-08 10:06     ` Gabriel Scherer
2014-11-30 15:49 ` Gerd Stolpmann
2014-12-01 10:09   ` Alain Frisch
2014-12-26 23:45     ` Jordo
2014-12-01  9:49 ` Jeremy Yallop
2014-12-08  9:35   ` Goswin von Brederlow
2014-11-30 15:53 Damien Guichard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).