[commit: packages/base] master: Implement foldl with foldr (b63face)

Joachim Breitner mail at joachim-breitner.de
Mon Feb 17 10:48:04 UTC 2014


Am Montag, den 17.02.2014, 10:22 +0000 schrieb Simon Marlow:
> This worries me a bit.  If foldl isn't inlined, I get a less efficient 
> version, so it has to be inlined everywhere.  So -O0 code gets worse, 
> and binary sizes for -O1+ get bigger - foldl, sum, and product are now 
> What I'm arguing is that we should have more flexibility to *not* inline 
> things (INLINABLE is much better than INLINE), and when not inlining 
> things we should be calling an efficient version of the function.  This 
> is why map is not defined in terms of foldr, for instance.

so you are arguing that we should do what is done for map, i.e. have the
old definition for foldl, make
        foldl k z0 xs = foldr (\v fn z -> fn (k z v)) id xs z0
a RULE [~0] and have another RULE [0] that does 
        foldr (\v fn z -> fn (k z v)) id xs z0 = foldl k z0 xs

Is that right?


Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0x4743206C
  Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20140217/cca40903/attachment-0001.sig>

More information about the ghc-devs mailing list