[Haskell-cafe] Copy on read

Matthew Naylor mfn-haskell-cafe at cs.york.ac.uk
Sun May 11 11:02:12 EDT 2008


> Uniqueness typing does not lead to in-place update.  If a value is  
> only used once, then there is no need to update it at all!

my understanding is that if a value is uniquely-typed then it is
statically known never to have more than one reference, thus it can be
modified in-place.  Some potential advantages seem to be:

  * Less heap is used, reducing the strain on the garbage collector.

  * Memory writes can sometimes be avoided. Imagine changing the value of
    a leaf in a large unique tree.  Only one memory write is required
    rather than N, where N is the length of the path to that leaf
    from the root.  Such paths can obviously be quite long when working
    with lists.  Also, the cost of rebuilding constructors with many
    fields -- only to change a single field -- could be expensive.

I wonder to what extent deforestation supersedes such optimisations.
This would be a good topic to raise with a Cleaner.  The paper Neil
mentions looks like a nice alternative to uniqueness typing -- and it
appears that there will be a FitA talk about it, this Thursday.

Matt.


More information about the Haskell-Cafe mailing list