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);; On Fri, Jan 23, 2015 at 12:03 AM, Jacques Garrigue < garrigue@math.nagoya-u.ac.jp> wrote: > The answer is simple: polymorphic variants can only accept one argument > (which may of course be a tuple). The other behavior would have required > a specific syntax for multi-parameter polymorphic variants, since there is > no information associated to the constructor for them. > > Jacques Garrigue > > On 2015/01/23 15:53, Jordan W wrote: > > > > The OCaml compiler allows distinguishing between variants that accept a > single tuple and variant types that accept several parameters. What looks > like a variant type accepting a tuple, is actually the later: > > > > type x = TwoSeparateArguments of int * int > > let tuple = (10,10) > > let thisWontWork = TwoSeparateArguments tuple;; > > >> Error: The constructor TwoSeparateArguments expects 2 argument(s), > but is > applied here to 1 argument(s) > > > > (* Notice the extra parens around the two ints *) > > type x = OneArgumentThatIsATuple of (int * int) > > let thisActuallyWorks = OneArgumentThatIsATuple tuple > > > > The extra parens distinguish at type definition time which of the two is > intended. > > > > But OCaml does some automatic massaging of the data that you supply to > constructor values. > > let _ = OneArgumentThatIsATuple (4, 5) > > let _ = TwoSeparateArguments (4, 5) > > > > No extra parens are required in this case. But OCaml does give you the > ability to annotate patterns and expressions with an "explicit_arity" > attribute which allows syntactic distinction between supplying two separate > parameters vs. one that happens to be a tuple. This is important for other > parser extensions that wish to treat the two distinctly. What OCaml allows > (explicit_arity attribute) works well enough. > > > > The only problem is that there doesn't seem to be a way to utilize the > same explicit_arity attributes with polymorphic variants. Such attributes > are not acknowledged by the type system. Is this intended? > > > > Taking a quick look at typecore.ml, explicit_arity appears to be > acknowledged on standard constructors but not polymorphic variants. > > > https://github.com/ocaml/ocaml/blob/6e85c2d956c8fd5b45acd70a27586e44bb3a3119/typing/typecore.ml > > > > It seems these should be brought to consistency. I will file a mantis > issue unless anyone believes this is intended. > > > > Thank you in advance. > > > > Jordan > > > > > > >