> Some time ago I requested some sort of explanation on which
> functions one
> should use to achive fusion. Now that GHC really fuses
> functions (which it
> didn't when I made my last request) I think it would be nice if you
> updated the user's guide with a list of functions that can be
> fused and
> how to use them.
Good point! I've added the following to the RULES documentation.
Simon
<sect2>List fusion
<p>
The RULES mechanism is used to implement fusion (deforestation) of common
list functions.
If a "good consumer" consumes an intermediate list constructed by a "good
producer", the
intermediate list should be eliminated entirely.
The following are good producers:
<itemize>
<item> List comprehensions
<item> Enumerations of @Int@ and @Char@ (e.g. ['a'..'z']).
<item> Explicit lists (e.g. @[True, False]@)
<item> The cons constructor (e.g @3:4:[]@)
<item> @++@
<item> @map@
<item> @filter@
<item> @iterate@, @repeat@
<item> @zip@, @zipWith@
</itemize>
The following are good consumers:
<itemize>
<item> List comprehensions
<item> @array@ (on its second argument)
<item> @length@
<item> @++@ (on its first argument)
<item> @map@
<item> @filter@
<item> @concat@
<item> @unzip@, @unzip2@, @unzip3@, @unzip4@
<item> @zip@, @zipWith@ (but on one argument only; if both are good
producers, @zip@
will fuse with one but not the other)
<item> @partition@
<item> @head@
<item> @and@, @or@, @any@, @all@
<item> @sequence_@
<item> @msum@
<item> @sortBy@
</itemize>
So, for example, the following should generate no intermediate lists:
<tscreen><verb>
array (1,10) [(i,i*i) | i <- map (+ 1) [0..9]]
</verb></tscreen>
RE: ANNOUNCEMENT: The Glasgow Haskell Compiler, version 4.04
Simon Peyton-Jones Mon, 16 Aug 1999 18:58:26 +0200 (MET DST)
- ANNOUNCEMENT: The Glasgow Haskell Compiler, version 4.0... Simon Marlow
- Re: ANNOUNCEMENT: The Glasgow Haskell Compiler, ve... Josef Sveningsson
- Re: ANNOUNCEMENT: The Glasgow Haskell Compiler, ve... Matthias Kilian
- Re: ANNOUNCEMENT: The Glasgow Haskell Compiler, ve... Peter White
- RE: ANNOUNCEMENT: The Glasgow Haskell Compiler, ve... Simon Marlow
- Simon Peyton-Jones
