Howdy! On the discord channel this morning, someone brought up the fact that in
type foo = | A of int*int | B of (int*int)
B are quite different.
A is a constructor taking two arguments, even though it looks like it takes a tuple, while
B actually takes a tuple.
This means that the two cannot be used interchangeably and in fact have different enough meanings to matter in a lot of contexts.
(This is confusing to a beginner because it would seem like the parentheses are just meaningless precedence grouping, but they aren’t, they’re syntactically quite significant, and it would seem like the
* in the
A case means “tuple” but it does not.)
I didn’t know about this distinction myself. I haven’t been using OCaml that long, but it has been long enough that I was surprised I never understood this difference before. It is not well explained in the documentation (or perhaps I simply missed it being pointed out), and it would probably be good to be much more explicit in the official manual, and for books like RWO to mention this prominently for beginners.