
On Wed, Apr 13, 2011 at 5:22 PM, Andrew n marshall
Is there a syntax or function to copy a record, but with select fields populated with new values? For example, extending LYAH's Car
let stang67 = Car {company="Ford", model="Mustang", year=1967} let stang68 = stang67 `mutate` Car {year=1968}
The classic solution is simply :
let stang68 = stang67 {year=1968}
but that is not very convenient (not at all in fact) when for instance you have several nested records or you want to base the "new" value of a field on its "old" value. Thus was invented the concept of "functional references" or "lenses" which extend this mechanism by a more complete and convenient protocol to copy a record with modification on some of its field. See http://hackage.haskell.org/package/fclabels http://www.cis.upenn.edu/~bcpierce/papers/newlenses-popl.pdf There are plenty of lenses packages on Hackage, I don't know which are more used, maybe some that uses them could help here ? -- Jedaï