Rule "and/build" not firing
For this function
isprime_1 :: Int -> Bool
isprime_1 n = n >= 2 &&
( and $ map (\t -> 0 < mod n t) $
[2 .. truncate $ sqrt $ fromIntegral n] )
rule "and/build" is not firing with ghc-7.10.3.
ghc-7.8.4 does fire the rule and produces much better (that is, non-allocating) code.
I can get good code with 7.10 if I replace "and" by
import GHC.Base (build)
{-# RULES
"und/build" forall (g::forall b.(Bool->b->b)->b->b) .
und (build g) = g (&&) True
#-}
{-# NOINLINE und #-}
und :: [Bool] -> Bool
und = foldr (&&) True
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.10.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |