From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Yaron Minsky <yminsky@cs.cornell.edu>
Cc: Pierre Weis <pierre.weis@inria.fr>,
caml-list <caml-list@yquem.inria.fr>,
Alain Frisch <alain@frisch.fr>
Subject: Re: [Caml-list] Compiler feature - useful or not?
Date: Fri, 16 Nov 2007 02:51:19 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.64.0711160223420.26516@martin.ec.wink.com> (raw)
In-Reply-To: <891bd3390711151630x238b8eddod5b7462d0fa1c735@mail.gmail.com>
On Thu, 15 Nov 2007, Yaron Minsky wrote:
> Most of what you said about quotient types made sense to me, but I must
> admit to being deeply confused about the nature of the change to the
> language. Consider the following trivial module and two possible
> interfaces.
>
> module Int = struct
> type t = int
> let of_int x = x
> let to_int x = x
> end
>
> module type Abs_int = sig
> type t
> val of_int : int -> t
> val to_int : t -> int
> end
>
> module type Priv_int = sig
> type t = private int
> val of_int : int -> t
> val to_int : t -> int
> end
>
> So, what is the difference between (Int : Abs_int) and (Int : Priv_int)?
Just like for other constructors of concrete types, "private" makes them
read-only, i.e. you can use them only in pattern-matching.
You can write
match (x : Priv_int.t) with 0 -> true | _ -> false
But not
(x : Priv_int.t) = 0
> For instance, can I write (Priv_int.of_int 3) + (Priv_int.of_int 5)?
No, Priv_int would have to define its own Priv_int.(+) function.
> Can
> you point to anything concrete I can do with the private version that I
> can't do with the abstract version? Is there any expression that is legal
> for one but not for the other?
You can do some pattern-matching over private versions of ints, strings,
chars, arrays, builtin lists, polymorphic variants, in addition to records
and variants, without the risk of passing such values to the wrong
function (if such wrong function expects a real "int" for instance).
You can't do any useful pattern matching with abstract types.
Martin
--
http://wink.com/profile/mjambon
http://martin.jambon.free.fr
next prev parent reply other threads:[~2007-11-16 1:51 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-13 23:41 Edgar Friendly
2007-11-14 0:08 ` [Caml-list] " Yaron Minsky
2007-11-14 0:21 ` Martin Jambon
2007-11-14 7:58 ` Pierre Weis
2007-11-14 12:37 ` Alain Frisch
2007-11-14 13:56 ` Virgile Prevosto
2007-11-14 14:35 ` Pierre Weis
2007-11-14 16:38 ` Alain Frisch
2007-11-14 18:43 ` Pierre Weis
2007-11-14 19:19 ` Edgar Friendly
2007-11-15 6:29 ` Alain Frisch
2007-11-15 13:26 ` Pierre Weis
2007-11-15 17:29 ` Edgar Friendly
2007-11-15 20:28 ` Fernando Alegre
2007-11-16 0:47 ` Brian Hurt
2007-11-15 22:37 ` Michaël Le Barbier
2007-11-15 22:24 ` Michaël Le Barbier
2007-11-16 0:30 ` Yaron Minsky
2007-11-16 1:51 ` Martin Jambon [this message]
2007-11-16 9:23 ` Alain Frisch
2007-11-16 14:17 ` rossberg
2007-11-16 15:08 ` Martin Jambon
2007-11-16 16:43 ` Martin Jambon
2007-11-16 16:46 ` Till Varoquaux
2007-11-16 17:27 ` Edgar Friendly
2007-11-16 17:47 ` Martin Jambon
2007-11-16 17:54 ` Edgar Friendly
2007-11-16 18:10 ` Fernando Alegre
2007-11-16 19:18 ` David Allsopp
2007-11-16 19:32 ` Fernando Alegre
2007-11-16 19:50 ` Gerd Stolpmann
2007-11-16 17:31 ` Fernando Alegre
2007-11-16 17:43 ` Edgar Friendly
2007-11-16 0:46 ` Christophe TROESTLER
2007-11-16 8:23 ` Andrej Bauer
2007-11-16 8:58 ` Jean-Christophe Filliâtre
2007-11-16 9:13 ` Andrej Bauer
2007-11-16 9:48 ` Christophe TROESTLER
2007-11-14 16:57 ` Edgar Friendly
2007-11-14 21:04 ` Pierre Weis
2007-11-14 22:09 ` Edgar Friendly
2007-11-15 0:17 ` Jacques Garrigue
2007-11-15 6:23 ` Edgar Friendly
2007-11-15 10:53 ` Vincent Hanquez
2007-11-15 13:48 ` Jacques Carette
2007-11-15 14:43 ` Jon Harrop
2007-11-15 16:54 ` Martin Jambon
2007-11-14 16:09 ` Edgar Friendly
2007-11-14 16:20 ` Brian Hurt
2007-11-14 11:01 ` Gerd Stolpmann
2007-11-14 10:57 ` Jon Harrop
2007-11-14 14:37 ` Zheng Li
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=Pine.LNX.4.64.0711160223420.26516@martin.ec.wink.com \
--to=martin.jambon@ens-lyon.org \
--cc=alain@frisch.fr \
--cc=caml-list@yquem.inria.fr \
--cc=pierre.weis@inria.fr \
--cc=yminsky@cs.cornell.edu \
/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