[Haskell-cafe] Syntax for modifying nested product types

Christian Maeder maeder at tzi.de
Fri Apr 23 13:22:13 EDT 2004

Malcolm Wallace wrote:
>     perhaps cond f field = if cond then f field else field
>     foo { bar = perhaps cond0 f (bar foo)
>         , wib = perhaps cond1 g (wib foo) }

I tend to write functions:

upd_bar f x = x { bar = f (bar x) }
upd_wib f x = x { wib = f (wib x) }

in order to avoid mentioning the field names twice later on. Does it 
cost much if I sometimes supply "id" as update argument?

It would be nice if such update functions could be generated or if there 
were another special update syntax. Does it exist in other languages?

Cheers Christian

More information about the Haskell-Cafe mailing list