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