From: brogoff <brogoff@speakeasy.net>
To: Jon Harrop <jon@jdh30.plus.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Phantom types
Date: Wed, 25 Aug 2004 14:03:30 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0408251323260.1961@shell2.speakeasy.net> (raw)
In-Reply-To: <200408231049.59342.jon@jdh30.plus.com>
On Mon, 23 Aug 2004, Jon Harrop wrote:
> On Saturday 31 July 2004 17:31, Markus Mottl wrote:
> > module type PHANTOM_INT = sig
> > type 'p t
> > ...
>
> Right, I've had a bit more of a chance to play with phantom types now, and I'm
> quite confused. :-)
>
> As far as I can tell, there were a few errors in Markus' original (I may well
> be wrong, of course), so here is my altered version:
[...snip...]
Yes, those look like errors, and your fixes look good.
> So I've changed the types to be [ `Even ] instead of [> `Even ] and the "make"
> functions to be "int -> ...". This appear to work as desired:
that's what you want in this example.
> Now, there are some subtle peculiarities of these which I don't understand.
> Firstly, the type checking of the phantom types only seems to work if the
> type is made abstract in the module signature. I can't think why this should
> make a difference though. For example, changing "type 'p t" to "type 'p t =
> int" in "PhantomInt : sig" then allows:
>
> # PhantomInt.add_even_even i j;;
> - : [ `Even ] PhantomInt.t = 5
>
> which is clearly undesirable.
This looks like a bug in the OCaml type checker. It also occurs if you replace
the polymorphic variants with type even = Even and odd = Odd. It remains if
you replace the phantom type int by int64 or even int array, but goes away when
you replace the phantom type by type 'p t = { data = int } or
type 'p t = Int int. So the built in types appear to be being treated
differently.
> Secondly, specifying the types as Markus did (e.g. [> `Even]), which I think
> should have been correct, leads to some kind of monomorphic type:
>
> # PhantomInt.add_even_odd i j;;
> - : _[> `Odd ] PhantomInt.t = <abstr>
A [> or [< means there's an implicit type variable.
-- Brian
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2004-08-25 21:03 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-31 8:56 [Caml-list] const equivalent for mutable types? Christopher A. Gorski
2004-07-31 9:24 ` Jean-Marie Gaillourdert
2004-07-31 10:24 ` Jean-Marie Gaillourdert
2004-07-31 10:50 ` Markus Mottl
2004-07-31 14:31 ` Brian Hurt
2004-07-31 15:51 ` Markus Mottl
2004-07-31 17:05 ` skaller
2004-07-31 10:34 ` Markus Mottl
2004-07-31 13:44 ` Jon Harrop
2004-07-31 16:31 ` [Caml-list] Phantom types Markus Mottl
2004-08-23 9:49 ` Jon Harrop
2004-08-23 12:25 ` [Caml-list] Why does ocaml use custom buffering? Daan Leijen
2004-08-23 15:16 ` [Caml-list] Phantom types Jon Harrop
2004-08-27 9:03 ` Jacques GARRIGUE
2004-08-25 21:03 ` brogoff [this message]
2004-07-31 16:35 ` [Caml-list] const equivalent for mutable types? skaller
2004-07-31 17:23 ` [Caml-list] Functional arrays Jon Harrop
2004-07-31 18:45 ` skaller
2004-08-02 5:07 ` brogoff
2004-08-02 7:45 ` Diego Olivier Fernandez Pons
2004-08-05 16:42 ` Daniel Ortmann
2004-08-05 17:02 ` Diego Olivier Fernandez Pons
2004-08-05 17:16 ` Diego Olivier Fernandez Pons
2004-07-31 17:45 ` [Caml-list] const equivalent for mutable types? Chris Gorski
2004-07-31 14:11 ` Brian Hurt
2010-05-17 14:59 Phantom types Thomas Braibant
2010-05-17 16:37 ` [Caml-list] " Goswin von Brederlow
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.58.0408251323260.1961@shell2.speakeasy.net \
--to=brogoff@speakeasy.net \
--cc=caml-list@inria.fr \
--cc=jon@jdh30.plus.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