[Haskell-cafe] Record update fusion (or how should I call it?)

Alberto G. Corona agocorona at gmail.com
Sun Sep 6 15:19:01 EDT 2009


Use Haskell records:

defaultWindowDescription= WindowDescription {title="", size=(0,0) ......}

Many modifications can be fused in a single statement. for example:

newWindowDescription= defaultWindowDescription{itle= "Haskell" ; size=
(640,480),background= Blue}



2009/9/6 Derek Elkins <derek.a.elkins at gmail.com>:
> The first thing I would do i is verify that the compiler is not
> already doing this.
>
> On Sun, Sep 6, 2009 at 7:50 AM, Peter Verswyvelen<bugfact at gmail.com> wrote:
>> I've seen a couple of package being announced that provide first class
>> labels, and other packages already existed for this (Grapefruit
>> Record, HList, Accessor, ...)
>>
>> Regarding this, I have a question about the performance of multiple
>> composed field updates. Maybe an example.
>>
>> Suppose I have a large record - say WindowDescription - which contains
>> a lot of fields.
>>
>> Suppose I have a couple of default window description values, e.g.
>> defaultWindowDesc, dialogBoxDesc, etc
>>
>> Using accessors it is easy to take such a default value, and "modify"
>> a couple of fields, like:
>>
>> let myWindowDesc = set title "Haskell" . set size (640,480) . set
>> background Blue . set fontFamily Arial $ defaultWindowDesc
>>
>> However, I guess this would make a lot of intermediate
>> WindowDescription copies no (whether the fields are strict or not)? So
>> ideally for performance, all these "updates" should be fused, maybe
>> running inside an ST monad?
>>
>> I'm not sure if any of this is valid, but I would like to understand
>> more about this, so any links and hints are welcome :-)
>>
>> Peter Verswyvelen
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
> _______________________________________________
> 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