From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: David Allsopp <dra-news@metastack.com>
Cc: "'David Rajchenbach-Teller'" <David.Teller@univ-orleans.fr>,
"'Grégoire Seux'" <kamaradclimber@gmail.com>,
'caml-list' <caml-list@inria.fr>
Subject: Re: [Caml-list] define incompatible type
Date: Fri, 12 Feb 2010 21:26:27 +0100 [thread overview]
Message-ID: <4B75B973.1000405@citycable.ch> (raw)
In-Reply-To: <00b001caabd2$63c57fd0$2b507f70$@romulus.metastack.com>
David Allsopp a écrit :
> David Rajchenbach-Teller wrote:
>> Hi Grégoire,
>> It's not directly possible in OCaml, but there are at least three methods
> for doing what you
>> want.
>>
>> The first one is to wrap your integers behind a constructor, e.g.
>
> <snip>
>
> You can also use (post OCaml 3.11.0) private types if you want to be able to
> use the ID values as integers but only explicitly.
Private types is indeed the way to go.
For instance, imagine that you have value wrapping C pointers. You may
want to declare something like:
> type pointer
> type type_1 = private pointer
> type type_2 = private pointer
When you write your code, you essentially use only types type_1 and
type_2. The type inference system won't look into the "private" part of
the type, so the type checker will cough on something like
> function (x : type_1) (y : type_2) -> x = y
But, you can subtype (i.e. use :> to tell the typechecker to use the
private declaration). And this will be valid OCaml:
> function (x : type_1) (y : type_2) -> (x :> pointer) = (y :> pointer)
--
Guillaume Yziquel
http://yziquel.homelinux.org/
next prev parent reply other threads:[~2010-02-12 20:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-12 6:32 Grégoire Seux
2010-02-12 7:33 ` [Caml-list] " David Rajchenbach-Teller
2010-02-12 7:43 ` Grégoire Seux
2010-02-12 10:59 ` David Allsopp
2010-02-12 20:26 ` Guillaume Yziquel [this message]
2010-02-12 9:25 abau
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=4B75B973.1000405@citycable.ch \
--to=guillaume.yziquel@citycable.ch \
--cc=David.Teller@univ-orleans.fr \
--cc=caml-list@inria.fr \
--cc=dra-news@metastack.com \
--cc=kamaradclimber@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