From: simonpj Date: Mon, 16 Aug 1999 16:25:12 +0000 (+0000) Subject: [project @ 1999-08-16 16:25:12 by simonpj] X-Git-Tag: Approximately_9120_patches~5897 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=41e360109b95883642b6856150a9cca81687f8c0;p=ghc-hetmet.git [project @ 1999-08-16 16:25:12 by simonpj] Add notes about what list fusion is done --- diff --git a/ghc/docs/users_guide/glasgow_exts.vsgml b/ghc/docs/users_guide/glasgow_exts.vsgml index ce0fc91..96318c4 100644 --- a/ghc/docs/users_guide/glasgow_exts.vsgml +++ b/ghc/docs/users_guide/glasgow_exts.vsgml @@ -1,5 +1,5 @@ % -% $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. 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 declarations. +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: + + List comprehensions + Enumerations of @Int@ and @Char@ (e.g. ['a'..'z']). + Explicit lists (e.g. @[True, False]@) + The cons constructor (e.g @3:4:[]@) + @++@ + @map@ + @filter@ + @iterate@, @repeat@ + @zip@, @zipWith@ + + +The following are good consumers: + + List comprehensions + @array@ (on its second argument) + @length@ + @++@ (on its first argument) + @map@ + @filter@ + @concat@ + @unzip@, @unzip2@, @unzip3@, @unzip4@ + @zip@, @zipWith@ (but on one argument only; if both are good producers, @zip@ +will fuse with one but not the other) + @partition@ + @head@ + @and@, @or@, @any@, @all@ + @sequence_@ + @msum@ + @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. Controlling what's going on