[Haskell-cafe] Syntax for modifying nested product types

Mark Carroll mark at chaos.x-philes.com
Thu Apr 22 19:18:44 EDT 2004

I have data objects where each component is a labelled field through which
I access or modify it. I have a hierarchy of these - many of the fields
are themselves such data objects, so I may need to apply a few selector
functions to get down to what I want (call these "deep").

For fairly flat things, the updates using field labels are okay. However,
when I have a function that needs to tweak various bits of various "deep"
fields, based on various conditions, then it gets really ugly, not least
because of the conditions: foo { bar = baz } becomes,
let old = bar foo in foo { bar = if cond then f old else old }
or whatever. Do I need such a let for each component and sub-component of
the object that has a child that may be modified, or will
foo { bar = if cond then f (bar foo) else bar foo }
be suitably optimised? (The if's inside the {} because there may be
multiple fields (or children thereof) being modified based on different

-- Mark

More information about the Haskell-Cafe mailing list