I'm trying to use an as-pattern to decompose a tuple value, and am observing some weird parsing/typing behaviour. Example fsi (4.0) run:
> let t = (0, (1, 2), 3) in let (_, (_, _) as pair, _) = t in ();;
let t = (0, (1, 2), 3) in let (_, (_, _) as pair, _) = t in ();;
-------------------------------------------------------^
stdin(9,56): error FS0001: Type mismatch. Expecting a
('a * ('b * 'c)) * 'd
but given a
int * (int * int) * int
The type ''a * ('b * 'c)' does not match the type 'int'
However, the example works if I put in some additional ():
> let t = (0, (1, 2), 3) in let (_, ((_, _) as pair), _) = t in ();;
val it : unit = ()
Is this me being slightly daft, or is the parser misbehaving in the first example? I guess it tries to apply the "as pair" to ", (, _)", which is slightly more greedy than seems right.
,
has higher precedence thanas
that's why you need additional(
,)
inyou can see this from the error:
it tells you basically that misplaced some parentheses ;)