I'm trying to define primes using just list comprehension. The following works.Prelude> odds = [3, 5..]Prelude> primes = 2 : [p | p <- odds, null [d | d <- take (p `div` 4) odds, p `mod` d == 0]]But when I replace "take (p `div` 4)" with takeWhile (<=(sqrt p)) as inPrelude> primes' = 2 : [p | p <- odds, null [d | d <- (takeWhile (<=(sqrt p)) odds), p `mod` d == 0]]I get no error message on entering the statement, but when I runPrelude> take 8 primes'I get an error message that I can't understand.<interactive>:23:1: error:• Ambiguous type variable ‘a0’ arising from a use of ‘it’prevents the constraint ‘(Floating a0)’ from being solved.Probable fix: use a type annotation to specify what ‘a0’ should be.These potential instances exist:instance Floating Double -- Defined in ‘GHC.Float’instance Floating Float -- Defined in ‘GHC.Float’• In the first argument of ‘print’, namely ‘it’In a stmt of an interactive GHCi command: print itI tried using (ceiling (sqrt p)), and I tried to explicitly declare it an Int, but neither of those helped.I'd appreciate some help.Thanks.P.S. The following runs fine.Prelude> takeWhile (<= (sqrt 99)) oddsSo I'm completely stumped.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners