David Allsopp, could you please include me on the "Reply" so that the mail threads make their way to my inbox?
David, are you certain that the explicit_arity attribute is only related to type declarations? I do not believe that to be the case. I understand them to apply to patterns and expressions as well.
(* Declares a variant that accepts a *single* parameter *)
type oneArgTuple = OneArg of (int*int)
(* Works because arity is massaged into whatever is necessary and doesn't need to be expressed at parse time. *)
let OneArg (x,y) = OneArg (1,2)
(* But you can *explicitly* enforce arity and tell the type system that this tuple should be treated as multiple arguments *)
(* That causes this to fail type checking on this tuple pattern! *)
let (OneArg (x,y) [@explicit_arity]) = OneArg (1,2);;
>> Error: The constructor OneArg expects 1 argument(s),
>> but is applied here to 2 argument(s)
(* Similarly, at parse time, you can tell the parser to parse an expression as being multiple arguments *)
let result = OneArg (1,2)[@explicit_arity];;
>> Error: The constructor OneArg expects 1 argument(s),
>> but is applied here to 2 argument(s)
So the fact that you can inform the parser to treat a tuple as multiple arguments to a Constructor, means that the same should be true of polymorphic variants, but it is not. For example, this type checks but it shouldn't:
let (`MyThing (x,y) [@explicit_arity]) = `MyThing (2,2);;