From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 73196BC37 for ; Fri, 12 Feb 2010 21:25:59 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As4AACZIdUtV2gB4mWdsb2JhbACDBJgSAQEBAQEICwoHEyOwFI85gS+CTlsEiWA X-IronPort-AV: E=Sophos;i="4.49,463,1262559600"; d="scan'208";a="44576962" Received: from emailfrontal1.citycable.ch ([85.218.0.120]) by mail2-smtp-roc.national.inria.fr with SMTP; 12 Feb 2010 21:25:59 +0100 Received: from [192.168.0.12] (unknown [85.218.92.99]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal1.citycable.ch (Postfix) with ESMTPA id C406612C470; Fri, 12 Feb 2010 21:25:57 +0100 (CET) Message-ID: <4B75B973.1000405@citycable.ch> Date: Fri, 12 Feb 2010 21:26:27 +0100 From: Guillaume Yziquel Reply-To: guillaume.yziquel@citycable.ch User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: David Allsopp Cc: 'David Rajchenbach-Teller' , =?UTF-8?B?J0dyw6lnb2lyZSBTZXV4Jw==?= , 'caml-list' Subject: Re: [Caml-list] define incompatible type References: <1ae8fe881002112232v73a57e97le63cfd48ffac6d48@mail.gmail.com> <8D169DE8-B24E-4A80-8D2D-3743B6EF9A7A@univ-orleans.fr> <00b001caabd2$63c57fd0$2b507f70$@romulus.metastack.com> In-Reply-To: <00b001caabd2$63c57fd0$2b507f70$@romulus.metastack.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; guillaume:01 guillaume:01 ocaml:01 integers:01 ocaml:01 integers:01 pointers:01 pointer:01 pointer:01 inference:01 checker:01 subtype:01 typechecker:01 wrote:01 incompatible:01 David Allsopp a =C3=A9crit : > David Rajchenbach-Teller wrote: >> Hi Gr=C3=A9goire, >> It's not directly possible in OCaml, but there are at least three met= hods > for doing what you >> want. >> >> The first one is to wrap your integers behind a constructor, e.g. >=20 > >=20 > You can also use (post OCaml 3.11.0) private types if you want to be ab= le 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=20 want to declare something like: > type pointer > type type_1 =3D private pointer > type type_2 =3D private pointer When you write your code, you essentially use only types type_1 and=20 type_2. The type inference system won't look into the "private" part of=20 the type, so the type checker will cough on something like > function (x : type_1) (y : type_2) -> x =3D y But, you can subtype (i.e. use :> to tell the typechecker to use the=20 private declaration). And this will be valid OCaml: > function (x : type_1) (y : type_2) -> (x :> pointer) =3D (y :> pointer) --=20 Guillaume Yziquel http://yziquel.homelinux.org/