Inlining of `any @[]` vs `elem @[]`

ÉRDI Gergő gergo at erdi.hu
Fri Mar 12 10:02:00 UTC 2021


On Thu, 11 Mar 2021, Simon Peyton Jones wrote:

> With HEAD, and -O, I get the exact same (good code) for these two functions:
>
> 	f x = any (x ==) [1, 5, 7::Int]
>
> 	g x = elem x [2, 6, 9 :: Int]
>
> Maybe this is fixed?  If you think not, maybe open a ticket?

OK, so initially I tried it on GHC 8.10.3, which is where `elem @[]` is 
not optimized. I have now tried on GHC 9.0.1, where, just like you see on 
HEAD, indeed it gets it right.

I wonder why that is? What changed between GHC 8.10.3 and 9.0.1? Was the 
definition of `elem` changed in `base`?

Thanks,
 	Gergo


More information about the ghc-devs mailing list