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
Re: Bug converting numbers?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1998-09-14 (09:35)
From: Markus Mottl <mottl@m...>
Subject: Re: Bug converting numbers?
Hello - Bonjour!

> The problem here is that you missed the right equality predicate: you
> must use = instead of ==. Remember that == means unicity of
> representation, not semantical equality of values. For instance:

> Remember that the == predicate is not for casual uses: you should know
> something about value representations in your Caml system to use it
> safely. In doubt, use the regular = predicate.

Ah, everything clear! Having programmed in other languages lately, where
'==' means semantical equality, I easily read over this bug, although
I knew that there exist two operators for testing semantic equality or
representational identity respectively in Ocaml.

Especially, because:

# 1 == 1;;
- : bool = true


# 1.0 == 1.0;;
- : bool = false

This is certainly not, what the casual Ocaml-user expects...

Since there are probably many Ocaml-users who also use languages where
'==' expresses semantic equality (C/C++ is not the only one - e.g. Haskell
also uses this operator), wouldn't it be a good idea to take a different
operator than '==' for checking representational identity? As I had to
realize, such bugs can be really hard to track down. And since this
operator is probably not so often in use in "normal" Ocaml-programs,
it would not really effect too many developers.

Best regards,
Markus Mottl


Beaucoup de programmeurs en Ocaml aussi écrivent aux langues ou '=='
exprime l'égalité sémantique.  Ne serait-il pas une bonne idée de
prendre un operateur différent en place de "==" pour exprimer l'identité
de représentation en Ocaml? Comme je ai du voir, il peut être très
difficile de trouver des erreurs de cette sorte.
Parce-que ce n'est pas un operateur souvant utilisé, je ne crois pas
que ce changement aie un effet fort aux developeurs.

Markus Mottl

*  Markus Mottl              |  University of Economics and       *
*  Department of Applied     |  Business Administration           *
*  Computer Science          |  Vienna, Austria                   *
*  |  *