F # assigns function arguments using pattern matching. That's why
let g (a,b) = a + b
g (7,4)
works: The tuple maps to (a, b), and a and b are available directly inside f.
Doing the same with discriminated associations will be equally useful, but I cannot do this:
type A =
| X of int * int
| Y of string
let f A.X(a, b) = a + b
let f (A.X(a, b)) = a + b
f (A.X(7, 4))
Is pattern matching as part of a function call limited to tuples? Is there a way to do this with discriminatory unions?
source
share