[Haskell-beginners] Puzzling type error
Logesh Pillay
lpillay at webafrica.org.za
Sun Aug 24 13:38:48 EDT 2008
I've written the following implementation of the algorithm in this
article http://www.afjarvis.staff.shef.ac.uk/maths/jarvisspec02.pdf
sqRoot n scale = sqRoot' (5*n) 5
where
sqRoot' a b
| floor (logBase 10 b) >= scale = div b 10
| a >= b = sqRoot' (a-b) (b+10)
| otherwise = sqRoot' (a*100) ((100 * (div b
10)) + (mod b 10))
Since this involves whole numbers only, I was surprised by the following
run-time error.
*Main> sqRoot 2 5
<interactive>:1:0:
Ambiguous type variable `t' in the constraints:
`RealFrac t' arising from a use of `sqRoot' at <interactive>:1:0-9
`Floating t' arising from a use of `sqRoot' at <interactive>:1:0-9
`Integral t' arising from a use of `sqRoot' at <interactive>:1:0-9
Probable fix: add a type signature that fixes these type variable(s)
What am I missing?
Logesh Pillay
More information about the Beginners
mailing list