From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2SBD8cI027027 for ; Mon, 28 Mar 2011 13:13:08 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIAACRskE1V2gB5mWdsb2JhbAClXwEBAQEBCAsLBxQlwnsNhVwEkGU X-IronPort-AV: E=Sophos;i="4.63,253,1299452400"; d="scan'208";a="103808371" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail1-smtp-roc.national.inria.fr with SMTP; 28 Mar 2011 13:13:02 +0200 X-Alinto-smtpauth-localdomain: Yes Received: from seldon (unknown [85.218.93.111]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal2.citycable.ch (Postfix) with ESMTPA id 6D8DE20C697; Mon, 28 Mar 2011 13:12:59 +0200 (CEST) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1Q49lF-0006HK-LP; Mon, 28 Mar 2011 12:33:25 +0200 Date: Mon, 28 Mar 2011 12:33:25 +0200 From: Guillaume Yziquel To: Alain Frisch Cc: caml-list Message-ID: <20110328103325.GH20598@localhost> References: <89643D7F-B0F9-4452-BBAF-0445D9D3CA4E@gmail.com> <639CCD2C-402F-4754-B942-B460FD908A95@gmail.com> <63968844-AD95-4359-80F0-E9E071CF6518@mpi-sws.org> <20110325164240.GT10028@localhost> <46B666E2-4575-4E79-ACF1-FE0789C0C76B@mpi-sws.org> <20110325190129.GU10028@localhost> <4D903E90.4080907@frisch.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <4D903E90.4080907@frisch.fr> User-Agent: Mutt/1.5.20 (2009-06-14) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p2SBD8cI027027 Subject: Re: [Caml-list] Re: module typing issue Le Monday 28 Mar 2011 à 09:53:52 (+0200), Alain Frisch a écrit : > On 03/25/2011 08:01 PM, Guillaume Yziquel wrote: > >type error = private int > > > >external get_error : unit -> error = "zzz" > > > >You get some error level that you can pattern match as an int, and this > >also enforces that all values of type error come from a call to > >get_error. > > You need to coerce explicitly from type error to type int (... :> > int), so this is not really different from defining error as an > abstract type and exposing a function error->int. > > -- Alain Yes, doesn't work for private ints. However, it works for stuff like that, though it's not exactly the same thing as a 'private int': # type t = private A | B;; type t = private A | B # let x : t = Obj.magic 0;; val x : t = A # match x with A -> true | _ -> false;; - : bool = true # A;; Error: Cannot create values of the private type t I thought it also worked on for ints, and in a sense, I'm surprised that you cannot pattern match private ints as ints without a coercion. So for enumerating errors coming from C stubs, you can still do it this way. -- Guillaume Yziquel