[Haskell-beginners] Need Help

Michael Snoyman michael at snoyman.com
Sun Apr 12 23:29:05 EDT 2009


On Sat, Apr 11, 2009 at 3:16 PM, kaushal Pathak <kaushalkp at gmail.com> wrote:

>
>         first_div :: Integral a => a ; first_div = round (sqrt x)
>

Should in fact be

        first_div :: Integral a => a ; first_div = round (sqrt $
fromIntegral x)

Basically, sqrt has the type signature sqrt :: (Floating a) => a -> a,
meaning it only works on things like doubles. The rest of your code only
works on integral types. Your code compiles just fine because, in theory,
you could have a data structure which in an instance of both Integral and
Floating, but the argument you provide is probably just a regular old Int or
something like that (I can't be certain, as you have not provided the code
that calls isPrime1).

Let me know if you'd like further clarification.

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090413/39540c00/attachment.htm


More information about the Beginners mailing list