From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2SC4sAo030361 for ; Mon, 28 Mar 2011 14:04:54 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIAAAh5kE1V2gB5mWdsb2JhbAClYAEBAQEBCAsLBxQlwmoNgnCCbASQZQ X-IronPort-AV: E=Sophos;i="4.63,255,1299452400"; d="scan'208";a="95145553" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail2-smtp-roc.national.inria.fr with SMTP; 28 Mar 2011 14:04:30 +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 7F67320C6B5; Mon, 28 Mar 2011 14:04:29 +0200 (CEST) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1Q4B9K-0001kN-TZ; Mon, 28 Mar 2011 14:02:23 +0200 Date: Mon, 28 Mar 2011 14:02:22 +0200 From: Guillaume Yziquel To: David Allsopp Cc: Alain Frisch , caml-list Message-ID: <20110328120218.GX20598@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: 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 p2SC4sAo030361 Subject: Re: [Caml-list] Re: module typing issue Le Monday 28 Mar 2011 à 11:32:48 (+0000), David Allsopp a écrit : > Alain Frisch wrote: > > 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. > > Except that calling an identity function like that requires an optimising compiler to spot that the call is irrelevant and can be removed whereas the coercion is handled (and stripped out) during type inference. So although they're roughly equivalent, the private int approach is "neater" by several orders of magnitude (and as long as you only need an abbreviated coercion, a similar amount of keyboard-typing)! > > David True. But it seems that for most OCaml people, the weirdness of ':>' isn't worth the few CPU cycles. Haven't seen much code using :>. external "%identity" seems to be favoured. -- Guillaume Yziquel