# type foo = Foo of int * int
# let t = (1, 2)
# Foo t
Error: The constructor Foo expects 2 argument(s),
but is applied here to 1 argument(s)
How is it that I must do Foo (1, 2) to avoid that error even t has the appropriate type?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is one of the troubling parts of OCaml syntax, in my opinion. Despite the way it looks, the constructor Foo doesn’t require a 2-tuple as its argument. It requires, syntactically, two values in parentheses–but they aren’t a tuple. So it’s simply the case that
thas the wrong type. The way to make this work is to say:The problem really is that parentheses are being used for two different things (or so I claim). Once you get used to this it’s not so difficult to deal with.
Edit: if you want the constructor Foo to take a single tuple, rather than two separate values, you can define it like this:
Then the rest of your original code will work.