Gspia
Gspia

Reputation: 809

purescript anonymous function arguments on nested records?

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

Answers (1)

Phil Freeman
Phil Freeman

Reputation: 4169

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

updateU :: XName -> String -> XName
updateU = _ { xname { fname = _ } }

Upvotes: 4

Related Questions