Deforestation of literal lists

Carsten Schultz carsten at
Fri Sep 17 10:09:10 EDT 2004


Just a thought...

Would it be a sensible thing to not desugar

    [x, y, z]


    (:) x ((:) y ((:) z [])),

but into

    build (\ c n -> c x (c y (c z n)))?

Alternatively, how about the following rules?

{-# RULES 
  "singleton" [~1] forall x . (:) x [] = build (\c n -> c x n)

{-# RULES 
  "cons/build" [~1] forall (x::a) (f:: forall b . (a->b->b) -> b -> b) . 
      (:) x (build f) = build (\c n -> c x (f c n))

This should be useful for example in conjuction with sequence_ or //
applied to short lists.  Has this been discussed before?



Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
PGP/GPG key on the key servers, 
fingerprint on my home page.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url :

More information about the Glasgow-haskell-users mailing list