caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jordan W <jordojw@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Object Features
Date: Sat, 29 Nov 2014 20:24:32 -0800	[thread overview]
Message-ID: <CAPOA5_7BMBpK0g48upT4GqunPCC-JRcGkAg884X-6E9FbPjBpA@mail.gmail.com> (raw)

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

             reply	other threads:[~2014-11-30  4:24 UTC|newest]

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

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=CAPOA5_7BMBpK0g48upT4GqunPCC-JRcGkAg884X-6E9FbPjBpA@mail.gmail.com \
    --to=jordojw@gmail.com \
    --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).