[Haskell-cafe] more sharing in generated code

Andreas Abel andreas.abel at ifi.lmu.de
Sat Nov 3 10:47:09 CET 2012


On 03.11.12 10:05 AM, Peter Divianszky wrote:
> Suppose we have a record update
>
>    r { x = f (r x)}
>
> and suppose that most of the time f returns it's argument unchanged.
>
>     Recently I've heard about Q-combinators.
>     Central idea: Change (f :: a -> a) to (f' :: a -> Maybe a) returning
>     Nothing when the value didn't change.
>     Then we can replace the record update with smarter code which
>     preserves more sharing.

Just adding a remark here:  I actually played with these Q-combinators, 
they actually worsened performance of Agda.  The problem is that they 
make the code strict.  The performance loss due to strictness 
outweighted the potential performance gain by increased sharing. 
Q-combinators were developed by John Harrison in the context of ML, 
which is strict anyway.

I guess a compiler support for smart record update would not have the 
strictness penalty.

Cheers,
Andreas

-- 
Andreas Abel  <><      Du bist der geliebte Mensch.

Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY

andreas.abel at ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/



More information about the Haskell-Cafe mailing list