Why is (int*int) not the same thing as int*int in OCaml

Note that I’m not complaining about anything, I’m just curious about this unintuitive (at least to me) feature of OCaml, that (int*int) is not the same thing as int*int, as shown by the code below. I wonder if it serves a purpose, or is only an unintended consequence of the implementation chosen by the designers of OCaml ?

disk

2 Likes

The difference is subtle: https://stackoverflow.com/a/42691367/7443386

Thanks. Your link doesn’t answer my question directly, but I take from it that the “subtle difference” is simply a consequence of the internal representation of objects, and not something that the OCaml code writer can put to use to make his or her code more expressive.

The difference isn’t merely representation. One is a variant taking a tuple of two ints, the other is a variant taking two ints. Both allow you to store two ints in a variant, but they’re not the same thing. This has come up before: Sum type constructor declaration subtlety (and documentation wanted!)

You may find the following thread (and references therein) instructive:

https://inbox.ocaml.org/caml-list/87pozk6vjp.fsf@mid.deneb.enyo.de/

1 Like