caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jerome Vouillon <vouillon@clipper.ens.fr>
To: David Monniaux <monniaux@tulip.csl.sri.com>
Cc: caml-list@inria.fr
Subject: Re: inheritance for functor ?
Date: Fri, 4 Sep 1998 15:36:53 +0200	[thread overview]
Message-ID: <19980904153653.54796@clipper.ens.fr> (raw)
In-Reply-To: <199809040553.WAA25004@csla.csl.sri.com>; from David Monniaux on Thu, Sep 03, 1998 at 10:53:05PM -0700

On Thu, Sep 03, 1998 at 10:53:05PM -0700, David Monniaux wrote:
> Remark: it's not possible to hide a 'new classtype' function in a
> signature. That looks useful in certain circumstances, like mlgtk with
> its classes taking a pointer into a C structure as a
> parameter. However, this is not a must at all; after all, the library
> user is supposed to be big enough to understand that some functions
> shouldn't be used, period.

Actually, this is possible: if the class is declared virtual in the
signature of the module, 'new classtype' is not exported:
    # module M = struct class c = object end end;;
    module M : sig class c : object end end
    # module M1 : sig class virtual c : object end end = M;;
    module M1 : sig class virtual c : object end end
    # new M1.c;;
    One cannot create instances of the virtual class M1.c
It is also possible to only export the class type, therefore also
preventing inheritance:
    # module M2 : sig class type c = object end end = M;;
    module M2 : sig class type c = object end end

> Talking of which, what are the perspectives on variances? In ML-gtk, I
> have classes such as button, label, all descending from
> widget. Certain functions take a widget list as an argument. The
> problem is that the user has to do the casts manually:
> 
> [((foobar constructing a button) :> widget);
>  ((foobar constructing a label) :> widget)]
> 
> which is quite heavy. Is there any way to make it look better?

It is possible to write a function that coerce an object and add it to
a list :
    # let (<<) x y = (y :> widget) :: x;;
    val << : widget list -> < .. > -> widget list = <fun>
This way, coercions are hidden:
    [] << (foobar constructing a label) << (foobar constructing a button)

-- Jerome Vouillon





      reply	other threads:[~1998-09-04 17:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-26  8:27 Christophe Raffalli
1998-09-04  5:53 ` David Monniaux
1998-09-04 13:36   ` Jerome Vouillon [this message]

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=19980904153653.54796@clipper.ens.fr \
    --to=vouillon@clipper.ens.fr \
    --cc=caml-list@inria.fr \
    --cc=monniaux@tulip.csl.sri.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).