[Haskell-beginners] sqrt root issues
Bryce Verdier
bryceverdier at gmail.com
Wed Jun 30 23:01:41 EDT 2010
Hi all,
I'm having a real hard time wrapping my head around a problem;
Here is a basic, no frills, function.
prime divisor divided
| divided == 1 = True
| divisor== divided= True
| mod divided divisor== 0 = False
| otherwise = next_prime
where next_prime = prime (divisor + 2) divided
and the calling function:
is_prime input = prime 3 input
I'm trying to get the square root of input as an Integer.
In GHCI:
:t (toInteger $ round $ sqrt 25)
(toInteger $ round $ sqrt 25) :: Integer
but if I change is_prime input = prime 3 (toInteger $ round $ sqrt input)
I get this error:
problem3.hs:19:33:
No instance for (RealFrac Integer)
arising from a use of `round' at problem3.hs:19:33-37
Possible fix: add an instance declaration for (RealFrac Integer)
In the first argument of `($)', namely `round'
In the second argument of `($)', namely `round $ sqrt input'
In the expression: toInteger $ round $ sqrt input
problem3.hs:19:41:
No instance for (Floating Integer)
arising from a use of `sqrt' at problem3.hs:19:41-50
Possible fix: add an instance declaration for (Floating Integer)
In the second argument of `($)', namely `sqrt input'
In the second argument of `($)', namely `round $ sqrt input'
In the expression: toInteger $ round $ sqrt input
Failed, modules loaded: none.
Can someone please help me out and tell me what I'm missing?
Thanks in advance,
Bryce
More information about the Beginners
mailing list