caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jordo <jordojw@gmail.com>
To: Alain Frisch <alain@frisch.fr>
Cc: Gerd Stolpmann <info@gerd-stolpmann.de>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Object Features
Date: Fri, 26 Dec 2014 15:45:21 -0800	[thread overview]
Message-ID: <0435EEFC-C65E-47EF-95BA-573ED7856D52@gmail.com> (raw)
In-Reply-To: <547C3E49.7030809@frisch.fr>

Yes, this is primarily what I'm looking to do. The only question I have is whether or not the type annotation is required. Ideally, it would not be. This, along with some basic pattern matching ability would allow objects to be treated as a lightweight structurally subtyped records. Even if the use of "self" is limited or prohibited, I would still find tremendous use for them. OCaml objects are already so close to fulfilling this role, aside from these relatively small features. The presence of more advanced class features needn't add friction to using objects as more flexible records (at least that's the hope).

Have you taken a look at SuccessorML's extensible records? Also, Elm's records work in similar ways to what I'm describing (pattern matching and extension without requiring annotation). I've seen many new languages gain traction recently, many of them treating records as extensible, pattern matched and structurally subtyped. I realized that OCaml may have had something very close for a long time, but is missing a little bit of polish.

Sent from my iPhone

> On Dec 1, 2014, at 2:09 AM, Alain Frisch <alain@frisch.fr> wrote:
> 
>> On 11/30/2014 04:49 PM, Gerd Stolpmann wrote:
>> What could in deed be useful is a more light-weight construction that
>> layers objects, i.e. you define a new object around an existing one:
> 
> Indeed, being able to define an object by extending an existing one would be quite useful (perhaps overriding some methods, being understood that this doesn't affect late-bound calls from that object to itself).
> 
> I'd rather see that as a new kind of class expressions, say "of object <expr>", where <expr> could be an object expression (with a fixed type)
> so that you could write:
> 
> let new_object old_object =
>   object
>     inherit of object (old_object : t)
> 
>     method foo = ...
> 
>     method! bar = ...
>   end
> 
> This would also allow to merge two existing objects into one.
> 
> If <expr> has type < m1:t1; ...; mn: tn >, "of object <expr>" would be equivalent to
> 
>  let o = <expr> in
>  object
>    method m1 = o # m1
>    ...
>    method mn = o # mn
>  end
> 
> 
> 
> -- Alain

  reply	other threads:[~2014-12-26 23: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
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 [this message]
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=0435EEFC-C65E-47EF-95BA-573ED7856D52@gmail.com \
    --to=jordojw@gmail.com \
    --cc=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=info@gerd-stolpmann.de \
    /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).