On Tue, Sep 14, 2010 at 1:31 PM, Jonathan Geddes
<geddes.jonat...@gmail.com> wrote:
> With these extensions, couldn't I write the following?
>>someUpdate :: MyRecord -> MyRecord
>>someUpdate myRecord@(MyRecord{..}) = let
>>     { field1 = f field1
>>     , field2 = g field2
>>     , field3 = h filed3
>>     } in myRecord{..}

No, those are recursive let bindings!  If f = (1:), then field1 = [1,1,1,1...]

As Conrad suggests, use:

   someUpdate myRecord@(MyRecord{..}) = myRecord
      { field1 = f field1
      , field2 = f field2
      , field3 = f field3
      }

The reason this works is that "field1" in "field1 = " is not a real
scoped variable, but rather an identifier for a field in the record.
It's all somewhat subtle...

Luke
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to