Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
'exception Exc of (string * string)' and 'exception Exc of string * string' not necessarily the same #4182
Original bug ID: 4182
If you have in your .mli file this
exception Exc of (string * string)
and in your .ml file this
exception Exc of string * string
then ocamlc will complain that
Note that this problem doesn't occur for type definitions.
Hardly a major bug, but it is surprising, as typexpr and (typexpr) should be equivalent.
$ ocamlc -config
Comment author: @garrigue
exception E of string * string and exception E of (string * string) have different internal representations, so they are incompatible.
Comment author: cookedm
Responding to Colas:
Responding to garrigue:
The type expression ( typexpr ) denotes the same type as typexpr
I thought that was pretty clear :-)
The other problem is that the output produced by ocaml is the same for both
type t1 = E1 of string * string;;
type t1 = E1 of string * string
type t2 = E2 of (string * string);;
type t2 = E2 of (string * string)
E1 ("a", "b");;
E2 ("a", "b");;
so the pretty-printed version of the two values is identical.
Comment author: @oandrieu
cookedm: there is a difference between a constructor with one tuple argument (declared by "E of (string * string)" and a constructor with multiple arguments "E of string * string".
The revised syntax of camlp4 makes this distinction way more clear by using a different keyword for the multiple arguments case:
But I'm not sure where this is documented in the reference manual. Section 6.8.1, "Type definitions" says: "The constructor declaration constr-name of typexpr declares the name constr-name as a non-constant constructor, whose argument has type typexpr." It doesn't explain anything about constructors with multiple arguments.
Comment author: @damiendoligez
In fact, it's a bug in the documentation. typexpr and (typexpr) are indeed equivalent,
The documentation will be fixed in 3.10.0.