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] Functor implementation
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chris Clearwater <chris@s...>
Subject: Re: [Caml-list] Functor implementation
On Wed, Jul 23, 2003 at 03:01:32PM +0200, Xavier Leroy wrote:
> Now, let me warn you about the following code:
> > let compare x y =
>     let cmp = x - y in if cmp > 0 then GT else if cmp < 0 then LT else EQ
> which doesn't work if x and y are sufficiently far apart
> (e.g. x = max_int and y = min_int).
> - Xavier Leroy

Ahh, thanks, functors now fit nicely in my head. And yeah that cmp
function was kind of braindead. I dont know why I didnt simply write it
as : let cmp x y = if x > y then GT else if x < y then LT else EQ. But
it would still be nice if the built in comparison function returned a
sum type. And there was provided a helper function:
let comparison_of_int x = if x > 0 then GT else if x < 0 then LT else EQ.
Maybe "ordering" is a more appropriate name. Also, true and false appear
to be a sum type: type bool = True | False, except you can't have lower
case constructor names. Does this signal the fact that there is some
kind of limitation with having primitive sum types?

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