Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Single-case union types as strong typedefs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Single-case union types as strong typedefs
On Sat, 2004-10-23 at 13:39, David Brown wrote:
> On Sat, Oct 23, 2004 at 12:31:39PM +0900, Jacques Garrigue wrote:
> > The problem you describe only occurs when your single constructor has
> > only one argument.
> > Indeed, this would be nice to have the overhead compiled away.
> > I don't remember whether there was a concrete reason not to.
> Another reason is that is breaks compatibility with existing C bindings, or
> at least potentially does.

That problem would go away with the 'newtype' Jaques mentioned.

I'm curious about newtype, since it could do more,
and would have to I think, to be worthwhile ..

	newtype metres = float
	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?

How about using functors in Ocaml somehow .. make 'metres' just
an abstract type via a functor Make.length representing the 
typeclass of lengths?

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.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: