[Haskell-cafe] Record updates

Andrew Coppin andrewcoppin at btinternet.com
Sun Mar 29 05:13:59 EDT 2009


Haskell's record syntax is quite nice, for a number of reasons. However, 
suppose I have some record:

  data Foobar = Foobar {foo1, foo2, foo3...}

Now suppose that foo3 :: [Int], and I want to prepend 5 to it. I end up 
having to write something like

  let v1 = v0 {foo3 = 5 : (foo3 v0)}

If the field name isn't "foo" but something more descriptive, and the 
transformation to be applied to it is more intricate, you end up with 
quite a bit of code.

In summary, record syntax gives you a nice way of replacing the value of 
one field with something else, but no easy way to *modify* the existing 
value somehow.

Does anybody know of a way around this? Is there some trick I'm not 
seeing? Is there an extension or proposal that fixes this?



More information about the Haskell-Cafe mailing list