caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Damien Guichard" <alphablock@orange.fr>
To: "Caml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] Object Features
Date: Sun, 30 Nov 2014 16:53:56 +0100	[thread overview]
Message-ID: <512049485139066376@orange.fr> (raw)

[-- 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 --]

             reply	other threads:[~2014-11-30 15:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-30 15:53 Damien Guichard [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-11-30  4:24 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=512049485139066376@orange.fr \
    --to=alphablock@orange.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).