I am new to Haskell and need help in debugging my code.
I wrote the following function for calculating square roots using Newton's
method:
my_sqrt :: Float -> Float
my_sqrt x = improve 1 x
where improve y x = if abs (y * y - x) < epsilon
then y
else improve ((y + (x/y))/ 2) x
epsilon = 0.00001
This works for several examples that I tried out but goes into an infinite loop
for my_sqrt 96. How do I go about debugging this code in GHC or Hugs?
(The equivalent code is well-behaved on MIT Scheme)
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe