Take a look at Data.Accessor on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor-template
-- ryan On Sun, Mar 29, 2009 at 2:13 AM, Andrew Coppin <[email protected]> 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 > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe > _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
