From: "Raj Bandyopadhyay" <[EMAIL PROTECTED]>
Hi OCaml folk

I apologize if I've been asking too many questions on this list recently, but I'm working on a heavy OCaml application and need help sometimes.

I am having a disagreement with a colleague about how the equality operators in OCaml work and am trying to resolve it conclusively.

1) I understand that the '==' operator is basically a pointer comparison i.e. a==b true iff a and b are the same entity. Is this true?

There are some complications here. Firstly, NaN has multiple representations that may or may not be physically equal but is always structurally unequal to itself. Secondly, OCaml's implicit allocation can make "same entity" unclear, constant subexpressions (e.g. Some 3) may or may not be hoisted.

The only place I ever use == and != is when optimizing code in such a way that unexpected results from those functions result in slow but still correct code.

2) Where can I find the code implementing the '==' operator in the OCaml code?

Can you just compile it and look at the assembler? There are probably many different outputs depending upon the statically resolved types.

3) In case I do want to check object identity and can use the == operator, would it be faster to use '==', '=' or a match statement?

I believe the == operator would be fastest. More often that not, you want < and > so you end up augmenting your OCaml data structures with unique IDs anyway.

Note that physical equality does not even exist in SML and the designers of SML stand by that design decision. Perhaps it is best to avoid == in OCaml altogether.

Cheers,
Jon.

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to