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
check_pat TupleP[Variable "x",Variable "xx"];as(check_pat TupleP) [Variable "x",Variable "xx"];which is obviously something you do not want. Butcheck_pat (TupleP [Variable "x",Variable "xx"]);should work fine.TuplePis something that produces apatternfrom apattern list(i.e.,pattern list -> pattern) whereascheck_patexpects apattern.case, i.e., writefun check_pat Wildcard = 1 | check_pat (Variable _) = 2 | ....