From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 622B2BC0B for ; Sat, 6 Jan 2007 02:15:36 +0100 (CET) Received: from mail6.sea5.speakeasy.net (mail6.sea5.speakeasy.net [69.17.117.8]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l061FXr9017481 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Sat, 6 Jan 2007 02:15:35 +0100 Received: (qmail 12710 invoked from network); 6 Jan 2007 01:15:32 -0000 Received: from shell4.sea5.speakeasy.net ([69.17.116.5]) (envelope-sender ) by mail6.sea5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 6 Jan 2007 01:15:32 -0000 Date: Fri, 5 Jan 2007 17:15:32 -0800 (PST) From: brogoff To: Nathaniel Gray Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Question on writing efficient Ocaml. In-Reply-To: Message-ID: References: <200612281626.38328.jon@ffconsultancy.com> <1167326001.5338.0.camel@rosella.wigram> <20061229.150507.32045202.garrigue@math.nagoya-u.ac.jp> <200612291115.kBTBF9E26561@virtutech.se> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE X-Miltered: at discorde with ID 459EF835.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 mattias:01 mattias:01 ocaml:01 sig:01 val:01 val:01 struct:01 2007,:98 innocent:98 wrote:01 wrote:01 compile:01 caml-list:01 speakeasy:01 On Fri, 5 Jan 2007, Nathaniel Gray wrote: > On 12/29/06, Mattias Engdeg=E5rd wrote: > > Is there a reason for this? To my innocent eyes, code like > > > > type length =3D Length of int > > > > looks quite reasonable and could be useful at times. > > I agree. Sadly, the ocaml devs don't. > > http://caml.inria.fr/mantis/view.php?id=3D3978 > > As Xavier points out, one can use modules to hide basic types, but > this is pretty clumsy in practice. There's rumored to be a solution > using phantom types, but my attempts don't work: You need to use modules to make phantom types work. Something like this module type BOINK =3D sig type 'a t val inj : int -> 'a t val prj : 'a t -> int val plus : 'a t -> 'a t -> 'a t end;; module Boink : BOINK =3D struct type 'a t =3D int let inj n =3D n let prj t =3D t let plus x y =3D x + y end;; let f : string Boink.t =3D inj 20;; let g : int Boink.t =3D inj 30;; Boink.plus f g;; I didn't compile that, but you get the idea... -- Brian