0

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 } }
Gspia
  • 809
  • 6
  • 15

1 Answers1

4

The shortest version uses nested record updates and looks like this:

updateU :: XName -> String -> XName
updateU = _ { xname { fname = _ } }
Phil Freeman
  • 4,199
  • 1
  • 20
  • 15