Reputation: 809
Is it possible to apply anonymous function arguments to nested records somehow in the followign way?
type UName = {fname :: String, lname :: String}
type XName = { xname :: UName, addr :: String}
updateU = _ { xname : { fname : _ } } -- not ok
-- or
updateU = _ { xname.fname = _ } -- not ok
-- or
updateU = _ { xname : fname = _ } } -- not ok
Above trials say that context is invalid. Aim is to implement:
updateU = \x -> { xname : { fname : x } }
Upvotes: 0
Views: 145
Reputation: 4169
The shortest version uses nested record updates and looks like this:
updateU :: XName -> String -> XName
updateU = _ { xname { fname = _ } }
Upvotes: 4