caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Leo P White <lpw25@cam.ac.uk>
Cc: caml <caml-list@inria.fr>
Subject: Re: [Caml-list] [ANN] ocamlopen 1.0.2
Date: Thu, 12 Apr 2012 14:56:06 +0200	[thread overview]
Message-ID: <CAPFanBHbb1uKg3zTy7AsjCehtcofZhs-KJzCi5d7=J7B=+twJA@mail.gmail.com> (raw)
In-Reply-To: <Prayer.1.3.4.1204112213090.4991@hermes-2.csi.cam.ac.uk>

Is there a description somewhere of the semantics of your language change?


More specifically:

1. You link to a paper by Andres Löh and Ralf Hinze, how close are you
of their proposal?
They mention open datatypes and functions, you propose open datatypes,
but not open functions? That would be understandable because open
pattern matching is a bit fishy (best-fit matching etc...).

2. What is the difference between your "open" and "extensible"
datatypes? The visual difference is the present of initial
constructors in extensible cases, but you apparently make much finer
distinctions.

3. What is the semantics of making a *constructor* private? My
intuition of private types is that (type t = private u) generates a
new type t that is a strict subtype of u (values of type t can be
coerced into u, but not the other way around). This intuition does not
hold anymore if some constructors are marked private, but not the
other.


I have some further questions:

4. When would you say that one should use polymorphic variants rather
than your open datatypes? (I know how to argue in the other direction:
unique constructors make for better error messages.)

5. What are the implications of your patch at the runtime / data
representation level? Could you elaborate a bit more on "a new tag to
represent extensions"? Have you conducted performance measurements?


(I find your work interesting. I have not looked at the code yet,
because I think someone should be able to get answer to the questions
above without having to look at the patch.)

On Wed, Apr 11, 2012 at 11:13 PM, Leo P White <lpw25@cam.ac.uk> wrote:
> Hi,
>
> If anyone is interested, I have written a new version of my patch to add
> open extensible types to OCaml. It is available at:
>
> https://sites.google.com/site/ocamlopen/
>
> The only new feature is allowing variant declarations to be made extensible.
> This allows declarations like:
>
> open type foo = A | B of int | ..
>
> Having implemented it, I think that the extension might well be better off
> without this feature, so I am also releasing another version of the patch
> without it.
>
> I have also written a much better example of how open types and GADTs might
> be used. It basically shows how classes can be created that permit a kind of
> nominative down-casting. I have included it below.
>
> Finally, I have also added a feature request to Mantis if anyone would like
> to comment.
>
> http://caml.inria.fr/mantis/view.php?id=5584
>
> Regards,
>
> Leo
>
> --------------------------------
>
> open type 'a class_name
>
> exception Bad_cast
>
> class type castable =
> object
>  method cast: 'a.'a class_name -> 'a
> end
>
> (* Lets create a castable class with a name*)
>
> class type foo_t =
> object
>  inherit castable
>  method foo: string
> end
>
> extend 'a class_name with Foo: foo_t class_name
>
> class foo: foo_t =
> object(self)
>  method cast: type a. a class_name -> a =
>   function
>      Foo -> (self : #foo_t :> foo_t)
>     | _ -> ((raise Bad_cast) : a)
>  method foo = "foo"
> end
>
> (* Now we can create a subclass of foo *)
>
> class type bar_t =
> object
>  inherit foo
>  method bar: string
> end
>
> extend 'a class_name with Bar: bar_t class_name
>
> class bar: bar_t =
> object(self)
>  inherit foo as super
>  method cast: type a. a class_name -> a =
>   function
>       Bar -> (self : #bar_t :> bar_t)
>     | other -> super#cast other
>  method bar = "bar"
> end
>
> (* Now lets create a mutable list of castable objects *)
>
> let clist :castable list ref = ref []
>
> let push_castable (c: #castable) =
>  clist := (c :> castable) :: !clist
>
> let pop_castable () =
>  match !clist with
>     c :: rest ->
>       clist := rest;
>       c
>   | [] -> raise Not_found;;
>
> (* We can add foos and bars to this list, and retrive them *)
>
> push_castable (new foo);;
> push_castable (new bar);;
> push_castable (new foo);;
>
> let c1: castable = pop_castable ()
> let c2: castable = pop_castable ()
> let c3: castable = pop_castable ()
>
> (* We can also downcast these values to foos and bars *)
>
> let f1: foo = c1#cast Foo
> let f2: foo = c2#cast Foo
> let f3: foo = c3#cast Foo
>
> let b2: bar = c2#cast Bar
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2012-04-12 12:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-11 21:13 Leo P White
2012-04-12 12:56 ` Gabriel Scherer [this message]
2012-04-12 14:03   ` Alain Frisch
2012-04-12 14:16     ` Philippe Veber
2012-04-12 14:29       ` Alain Frisch
2012-04-17 10:02         ` Philippe Veber
2012-04-12 17:07   ` Leo P White
2012-04-12 17:21     ` Alain Frisch
2012-04-12 20:31       ` Leo P White

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='CAPFanBHbb1uKg3zTy7AsjCehtcofZhs-KJzCi5d7=J7B=+twJA@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=lpw25@cam.ac.uk \
    /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).