I have these two functions:
primes = sieve [2..]
where
sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p > 0]
isPrime number = number /= 1 && null [x | x <- takeWhile (\x -> x < (ceiling . sqrt) number) primes, mod number x == 0]
The thing is that when I'm trying to load module which contains those functions, I see following error message:
[2 of 2] Compiling Main ( euler37.hs, interpreted )
euler37.hs:6:70:
No instance for (RealFrac Int)
arising from a use of `ceiling'
Possible fix: add an instance declaration for (RealFrac Int)
In the first argument of `(.)', namely `ceiling'
In the expression: ceiling . sqrt
In the second argument of `(<)', namely `(ceiling . sqrt) number'
euler37.hs:6:80:
No instance for (Floating Int)
arising from a use of `sqrt'
Possible fix: add an instance declaration for (Floating Int)
In the second argument of `(.)', namely `sqrt'
In the expression: ceiling . sqrt
In the second argument of `(<)', namely `(ceiling . sqrt) number'
I really can't understand what's the problem, because when I'm trying to make a small function from piece of code, which, as far as I understand, cause these errors, right in ghci, like let f number x = x < (ceiling . sqrt) number I don't see any error messages.
UArray Int Bool), GHC does figure it out and it doesn't do too badly (much better than priority queue or treefold for a while) - I tried 6.12.3 and 7.2.2. It's of course much slower than a segmented sieve that fits into the L2 cache (and cache locality is why PQ and TF seemingly scale better than a monolithic sieve once you get to large ranges), and that transformation would be really hard for a compiler :)