Deforestation of literal lists

Simon Peyton-Jones simonpj at microsoft.com
Wed Sep 29 06:49:27 EDT 2004


Carsetn

This, plus your earlier message about unfold, certainly make sense.  But
with the rules below, there's a danger that long literal lists would
give rise to a huge nest of cons/build rule firings, which are
ultimately all undone again.  So I'm a bit cautious about building these
rules in.

But you can just add them yourself, by writing RULES.  (Use the rules in
the prelude for guidance).  If you get noticeable performance wins,
without obvious downside, then I'd certainly think about adding them to
GHC.

Simon

| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org
[mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of Carsten Schultz
| Sent: 17 September 2004 15:09
| To: glasgow-haskell-users at haskell.org
| Subject: Deforestation of literal lists
| 
| 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.


More information about the Glasgow-haskell-users mailing list