Deforestation of literal lists

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


Hi!

Just a thought...

Would it be a sensible thing to not desugar

    [x, y, z]

into

    (:) 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?

Greetings,

Carsten

-- 
Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
http://carsten.codimi.de/
PGP/GPG key on the pgp.net 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 : http://www.haskell.org//pipermail/glasgow-haskell-users/attachments/20040917/1873a558/attachment.bin


More information about the Glasgow-haskell-users mailing list