functional programming - Pattern matching on two records with the same fields -
say have record:
type alias rec = { : int }
and, example, function takes 2 of these , sums integers.
f: rec -> rec -> int
this can implemented using record accessors (i.e. f x y = x.a + y.a
), there way use pattern matching extract both integers?
obviously, these 2 not work because binding 2 different numbers same variable:
f {a} {a} = + f x y = case (x, y) of ({a}, {a}) -> +
there's no way currently. there pattern aliasing (as
) works whole pattern, invalid:
type alias rec = { : int } f: rec -> rec -> int f { xa } { ya } = xa + ya main = f { = 1 } { = 2 }
results in:
detected errors in 1 module. -- syntax problem -------------------------------------------------------------- ran unexpected when parsing code! 4| f { xa } { ya } = xa + ya ^ looking 1 of following things: closing bracket '}' whitespace
Comments
Post a Comment