caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Jordan W <jordojw@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Object Features
Date: Sun, 30 Nov 2014 16:49:25 +0100	[thread overview]
Message-ID: <1417362565.6436.88.camel@e130.lan.sumadev.de> (raw)
In-Reply-To: <CAPOA5_7BMBpK0g48upT4GqunPCC-JRcGkAg884X-6E9FbPjBpA@mail.gmail.com>

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

Am Samstag, den 29.11.2014, 20:24 -0800 schrieb Jordan W:

> 2. Object extension: I believe that OCaml immediate objects are fairly
> under-appreciated,

I wouldn't say so. As I'm not a big fan of inheritance immediate objects
are the simpler and more expressive of dealing with objects.

>  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.

Basically, the availability of inheritance is the big difference between
classes and functions returning immediate objects. As of now, you need
to define classes if you want extensibility. But inheritance is of
course more than that; in particular you can also override existing
methods (and that's what I in particular don't like about it, as this
leads to hard to understand program flows).

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:
Something like

let new_object (old_object : t) =
  object
    (* Define some new methods: *)
    method foo = ...

    (* And make all methods of old_object also available *)
    method _ = old_object # _

    (* This notation shall mean that we define all methods x as
       method x = old_object # x
       and do this for all methods from t that haven't been defined
       otherwise
    *)
  end

This is very different from inheritance, because you have an outer
object and an inner, and the interface of the inner object is respected
(i.e. if another method of old_object calls foo, it is sure it calls the
version of foo in old_object, and not the new definition in new_object).
And this layering or wrapping construction is of course compatible with
immediate objects.

Gerd

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  parent reply	other threads:[~2014-11-30 15:49 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 [this message]
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=1417362565.6436.88.camel@e130.lan.sumadev.de \
    --to=info@gerd-stolpmann.de \
    --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).