All pastes #2052622 Raw Edit

Mine

public text v1 · immutable
#2052622 ·published 2011-05-01 20:03 UTC
rendered paste body
-- file: primes.hs
allProducts :: (Num a) => [a] -> [a] -> [a]
allProducts [] _ = []
allProducts _ [] = []
allProducts (x:xs) (y:ys) = [x*y] ++ (allProducts [x] ys ++ allProducts xs (y:ys))

isPrime :: (Integral a) => a -> Bool
isPrime x = x `elem` (allProducts n n)
            where n = [ y | y <- [2..], y <= floor (sqrt x) ]

primes = filter isPrime [1..]

-- end file

Prelude>:l primes
[1 of 1] Compiling Main             ( primes.hs, interpreted )

primes.hs:8:45:
    Could not deduce (RealFrac a) from the context (Integral a)
      arising from a use of `floor' at primes.hs:8:45-58
    Possible fix:
      add (RealFrac a) to the context of the type signature for `isPrime'
    In the second argument of `(<=)', namely `floor (sqrt x)'
    In the expression: y <= floor (sqrt x)
    In a stmt of a list comprehension: y <= floor (sqrt x)

primes.hs:8:52:
    Could not deduce (Floating a) from the context (Integral a)
      arising from a use of `sqrt' at primes.hs:8:52-57
    Possible fix:
      add (Floating a) to the context of the type signature for `isPrime'
    In the first argument of `floor', namely `(sqrt x)'
    In the second argument of `(<=)', namely `floor (sqrt x)'
    In the expression: y <= floor (sqrt x)
Failed, modules loaded: none.