From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA08979; Tue, 14 Jan 2003 04:34:45 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA09281 for ; Tue, 14 Jan 2003 04:34:44 +0100 (MET) Received: from mel-rto6.wanadoo.fr (smtp-out-6.wanadoo.fr [193.252.19.25]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h0E3Yir03636 for ; Tue, 14 Jan 2003 04:34:44 +0100 (MET) Received: from mel-rta9.wanadoo.fr (193.252.19.69) by mel-rto6.wanadoo.fr (6.7.015) id 3E0C343F009DE26D; Tue, 14 Jan 2003 04:34:37 +0100 Received: from warp (80.14.218.65) by mel-rta9.wanadoo.fr (6.7.015) id 3E075B46009EDD1D; Tue, 14 Jan 2003 04:34:37 +0100 Message-ID: <001301c2bb7e$5e119840$41da0e50@warp> From: "Nicolas Cannasse" To: "Hal Daume III" , "Caml Mailing List" References: Subject: Re: [Caml-list] unboxing of unary datatypes Date: Tue, 14 Jan 2003 04:38:13 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hi all, > > I originally had a very calculation intensive program which used a data > type which looked like: > > > type foo = Foo of float > > I could just have easily used floats, but I wanted to ensure that I didn't > do anything stupid (like try to multiply a foo by a float), so I did this > boxing so the type-checker would help me out. Hi, What you might need here are shadow types. You can define in your ML source file: type foo = float let mfoo f f' = f *. f' (* or better let mfoo = ( *. ) *) and in your interface ( MLI file ) : type foo val mfoo : foo -> foo -> foo then, other modules trying to work with your foo will have to use your set of operators because they won't know what exactly is "foo". > Can someone explain this to me? Why doesn't the compiler optimize out the > constructor? Because they don't have the same C raw representation. There is one more indirection when you use a constructor. If you want to interface OCaml with C, you have to be sure that the compiler won't try to optimize things in an incompatible way ( that goes for all compilers I think... ) Nicolas Cannasse ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners