Browse thread
[Caml-list] equality over functional value
-
Georges Brun-Cottan
- Alain Frisch
- Jean-Christophe Filliatre
- Xavier Leroy
- David Monniaux
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...> |
| Subject: | Re: [Caml-list] equality over functional value |
Georges Brun-Cottan writes: > > Hi, > > A friend of mine is just starting with ocaml. He was puzzled by the > following result: > > # let a i = i;; > val a : 'a -> 'a = <fun> > # let b i = i;; > val b : 'a -> 'a = <fun> > # a=b;; > Uncaught exception: Invalid_argument "equal: functional value". > # a=a;; > - : bool = true > # > > That is 'a=a' does not return the expected exception. Actually it > first hit this "curiosity" when creating a polymorphic 'sort' function > on lists - and by applying it to a [sort;sort..] list. It worked. > > Is this a bug? I don't think this behavior is intentional, but it has an easy explanation: for better efficiency, the structural comparison function (in byterun/compare.c) first tries physical equality, and then structural equality if there is no physical equality. So in the case of a=a, the answer is true because of physical equality. Hope this helps, -- Jean-Christophe FILLIATRE mailto:Jean-Christophe.Filliatre@lri.fr http://www.lri.fr/~filliatr ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr