caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Wang <mail@philippewang.info>
To: Jordan W <jordojw@gmail.com>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Object Features
Date: Sun, 30 Nov 2014 14:45:19 +0100	[thread overview]
Message-ID: <CAAFfW_rVtiKHxpWRAPdBbcdh-yVpoGPb3T-p6CykkmzdSC=d=g@mail.gmail.com> (raw)
In-Reply-To: <CAPOA5_7BMBpK0g48upT4GqunPCC-JRcGkAg884X-6E9FbPjBpA@mail.gmail.com>

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; ..>} = x + y + delta
is a little shorter than something like
    let myFunction delta (o: <x:'a; y:'b; ..>) = o#x + o#y + delta
but, still, I don't really see something good in there.

Cheers,
Philippe Wang


On Sun, Nov 30, 2014 at 5:24 AM, Jordan W <jordojw@gmail.com> 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 = {<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

  reply	other threads:[~2014-11-30 13:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-30  4:24 Jordan W
2014-11-30 13:45 ` Philippe Wang [this message]
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

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='CAAFfW_rVtiKHxpWRAPdBbcdh-yVpoGPb3T-p6CykkmzdSC=d=g@mail.gmail.com' \
    --to=mail@philippewang.info \
    --cc=caml-list@inria.fr \
    --cc=jordojw@gmail.com \
    /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).