[Haskell-cafe] Record updates

Ryan Ingram ryani.spam at gmail.com
Sun Mar 29 05:40:55 EDT 2009

Take a look at Data.Accessor on hackage:


  -- ryan

On Sun, Mar 29, 2009 at 2:13 AM, Andrew Coppin
<andrewcoppin at btinternet.com> wrote:
> 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?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list