[commit: ghc] master: Replace some `length . filter` with `count` (02614fd)

Joachim Breitner mail at joachim-breitner.de
Sat Aug 6 00:43:54 UTC 2016


Am Freitag, den 05.08.2016, 22:41 +0000 schrieb git at git.haskell.org:
> commit 02614fd61f57b599c5e4fd5e85f00a4e1ce37bc7
> Author: Ömer Sinan Ağacan <omeragacan at gmail.com>
> Date:   Fri Aug 5 20:58:02 2016 +0000
>     Replace some `length . filter` with `count`

Well intended!

I wouldn’t be surprised if this is actually making the code worse,
considering that "count" is implemented in the “wrong”, stackeating way
(whereas lenght . filter could, thanks to list fusion, produce the
desired code)

count :: (a -> Bool) -> [a] -> Int
count _ [] = 0
count p (x:xs) | p x       = 1 + count p xs
               | otherwise = count p xs

I would say that the regression reported by 
confirms this, but T6048 is simply unreliable. So practically, it does
not seem to matter either way.

I’ll change the implementation of count.

(Although even then it is not clear that the change is a win, as
"length . filter" might fuse with the producer, whereas "count" without
a lot of extra hassle will not.)


Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttps://www.joachim-breitner.de/
  XMPP: nomeata at joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F
  Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160805/e7768896/attachment.sig>

More information about the ghc-devs mailing list