[Haskell-beginners] Copy record with mutations?

Andrew n marshall andrew.n.marshall at gmail.com
Fri Apr 22 02:37:01 CEST 2011

Thanks for the follow-up.

While I'm still getting used to reading/writing the numerous new 
operators/infix notations,  I've started looking into the Data.Accessor 
package.  Is this similar in scope to the lenses you're referring to?

On 4/14/11 11:14 AM, Chaddaï Fouché wrote:
> On Wed, Apr 13, 2011 at 5:22 PM, Andrew n marshall
> <andrew.n.marshall at gmail.com>  wrote:
>> 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 ?

More information about the Beginners mailing list