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 XAA01616; Sat, 23 Oct 2004 23:49:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA01177 for ; Sat, 23 Oct 2004 23:49:09 +0200 (MET DST) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.202]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9NLn9fb023743 for ; Sat, 23 Oct 2004 23:49:09 +0200 Received: by rproxy.gmail.com with SMTP id 79so245695rnk for ; Sat, 23 Oct 2004 14:49:08 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=rZJS0vwpWCarlLWRyPlL43G4cFlhpzMZDNeJPJnhzu7eVJO++L+gx0pPweo4DRcHuqpZkjm+ERPelZJ6h4TAUIkqjHJ7kKbP8Afy9nD2oKjzT1iVdJjz/7gW4jEPvM0exfY6UIlYeaC+sAV7uCmCIaLLQ3nVFCeVcd4sktAtl+E= Received: by 10.38.15.13 with SMTP id 13mr383857rno; Sat, 23 Oct 2004 14:49:08 -0700 (PDT) Received: by 10.38.65.58 with HTTP; Sat, 23 Oct 2004 14:49:08 -0700 (PDT) Message-ID: Date: Sat, 23 Oct 2004 14:49:08 -0700 From: Nathaniel Gray Reply-To: Nathaniel Gray To: skaller@users.sourceforge.net Subject: Re: [Caml-list] Single-case union types as strong typedefs Cc: David Brown , Jacques Garrigue , caml-list In-Reply-To: <1098507602.7584.163.camel@pelican.wigram> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <20041023.123139.106410806.garrigue@kurims.kyoto-u.ac.jp> <20041023033915.GA22739@old.davidb.org> <1098507602.7584.163.camel@pelican.wigram> X-Miltered: at nez-perce with ID 417AD1D5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 typedefs:01 2004:99 sourceforge:01 haskell:01 wrappers:01 simplistic:01 phantom:01 phantom:01 underlying:01 caltech:01 caltech:01 float:02 float:02 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On 23 Oct 2004 15:00:02 +1000, skaller wrote: > This: > newtype metres = float > meaning > type metres = Metres float > > means you have to define all the operations on 'metres' all > over again: > > let (++) (Metres x) (Metres y) = Metres (x .+ y) > > I'd guess in Haskell newtype can benefit from typeclasses? I would have to try writing some code to be sure it makes sense, but I envisioned this as more of a contract mechanism. It would be a way of making "semi-opaque" values without encapsulation guarantees but also without performance penalties. A function that needed to do any serious work with the underlying values would destruct the wrappers: let hypoteneuse (Metres x) (Metres y): metres = sqrt(x*x + y*y) > Actually for quantities, you'd use some phantom types > so you could represent products of the dimensions, > such as square metres too .. so the simplistic > constructor representation isn't very good. I'll have to read a bit about phantom types. Maybe they fit the bill. Cheers, -n8 -- >>>-- Nathaniel Gray -- Caltech Computer Science ------> >>>-- Mojave Project -- http://mojave.cs.caltech.edu --> ------------------- 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