caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Jacques Le Normand <rathereasy@gmail.com>
Cc: caml-list caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] polymorphic (<)
Date: Wed, 21 Apr 2010 14:31:55 -0700	[thread overview]
Message-ID: <4BCF6ECB.5050107@ens-lyon.org> (raw)
In-Reply-To: <o2lf74178431004211407iead735c7n99baf68662cea962@mail.gmail.com>

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/


      reply	other threads:[~2010-04-21 21:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-21 21:07 Jacques Le Normand
2010-04-21 21:31 ` Martin Jambon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BCF6ECB.5050107@ens-lyon.org \
    --to=martin.jambon@ens-lyon.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=rathereasy@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).