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

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

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

Joachim Breitner-2

Am Freitag, den 05.08.2016, 22:41 +0000 schrieb [hidden email]:
> commit 02614fd61f57b599c5e4fd5e85f00a4e1ce37bc7
> Author: Ömer Sinan Ağacan <[hidden email]>
> 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
  [hidden email]
  XMPP: [hidden email] • OpenPGP-Key: 0xF0FBF51F
  Debian Developer: [hidden email]
ghc-devs mailing list
[hidden email]

signature.asc (836 bytes) Download Attachment