Does != have meaning in OCaml?

you have experienced the difference between structural and physical equality.

<> is to = (structural equality) as != is to == (physical equality)

"odg" = "odg"  (* true  *)
"odg" == "odg" (* false *)

is false because each is instantiated in different memory locations, doing:

let v = "odg"
v == v (* true *)
v = v  (* true *)

Most of the time you’ll want to use = and <>.

edit about when structural and physical equality are equivalent:

You can use the what_is_it function and find out all the types that would be equal both structurally and physically. As mentioned in the comments below, and in the linked article, characters, integers, unit, empty list, and some instances of variant types will have this property.

Leave a Comment