Commit 41e36010 authored by simonpj's avatar simonpj
Browse files

[project @ 1999-08-16 16:25:12 by simonpj]

Add notes about what list fusion is done
parent acaa6e12
% $Id: glasgow_exts.vsgml,v 1.14 1999/08/16 15:53:50 simonpj Exp $
% $Id: glasgow_exts.vsgml,v 1.15 1999/08/16 16:25:12 simonpj Exp $
% GHC Language Extensions.
......@@ -2124,10 +2124,60 @@ policy is controlled by the per-simplification-pass flag @-finline-phase@n.
<item> All rules are implicitly exported from the module, and are therefore
in force in any module that imports the module that defined the rule, directly
or indirectly. (That is, if A imports B, which imports C, then C's rules are
in force when compiling A.) The situation is very like that for instance
in force when compiling A.) The situation is very similar to that for instance
<sect2>List fusion
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:
<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@
The following are good consumers:
<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@
So, for example, the following should generate no intermediate lists:
array (1,10) [(i,i*i) | i <- map (+ 1) [0..9]]
This list could readily be extended; if there are Prelude functions that you use
a lot which are not included, please tell us.
If you want to write your own good consumers or producers, look at the
Prelude definitions of the above functions to see how to do so.
<sect2>Controlling what's going on
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment