Reputation: 126
I have the following type:
datatype pattern = Wildcard
| Variable of string
| UnitP
| ConstP of int
| TupleP of pattern list
| ConstructorP of string * pattern
I am trying to create a function that accepts this type (simplified example):
fun check_pat p =
case p of
Wildcard => 1
| Variable x => 2
| TupleP ps => 3
| ConstructorP(_,p) => 4
| _ => 5
but get an error when I call it with TupleP like so:
check_pat TupleP[Variable "x",Variable "xx"];
Error:
stdIn:3.1-3.46 Error: operator and operand do not agree [tycon mismatch]
operator domain: pattern
operand: pattern list -> pattern
in expression:
check_pat2 TupleP
But if I set this TupleP type to a variable and call it with that variable I am able to get the intended result. Could anyone let me know why this is the case?
val x = TupleP[Variable "x",Variable "xx"];
check_pat x;
val it = 3 : int
Upvotes: 0
Views: 81
Reputation: 36486
As noted in comments, this:
check_pat TupleP[Variable "x",Variable "xx"]
parses as this:
(check_pat TupleP) [Variable "x",Variable "xx"]
rather than what you likely intended:
check_pat (TupleP [Variable "x",Variable "xx"])
Assigning TupleP [Variable "x",Variable "xx"]
to x
and then calling check_pat x
also ensures that check_pat
is called correctly.
Upvotes: 3