Version française
Home     About     Download     Resources     Contact us    
Browse thread
polymorphic (<)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin.jambon@e...>
Subject: Re: [Caml-list] polymorphic (<)
Jacques Le Normand wrote:
> Hello caml-list,
> Why doesn't (<) check for physical equality before traversing the
> structures?

If I remember correctly it used to be the case in older versions of OCaml, but
it changed because of the standard behavior expected from NaN float values.
The comparison of a NaN value with any other float should always return false,
and therefore the structural comparison of any data structure containing a NaN
with itself should also return false:

# let x = Some [ nan ];;
val x : float list option = Some [nan]

# x = x;;
- : bool = false

# x == x;;
- : bool = true


The solution to your problem is to use Pervasives.compare instead of the
comparison operators:

# compare x x;;
- : int = 0



Martin

-- 
http://mjambon.com/