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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -