-- Compute a better value: improve y x = (y + x/y) / 2 -- iteration: iter y x = if ok y x then y else iter (improve y x) x -- is the value ok? ok y x = abs (y*y - x) < 0.001 sqrootUgly x = iter 1 x ----------------------------------------------------------------- sqroot x = iter 1 where -- Compute a better value: improve y = (y + x/y) / 2 -- iteration: iter y = if good y then y else iter (improve y) -- is the value ok? good y = abs (y*y - x) < 0.001 f True = x ----------------------------------------------------------------- -- Number of elements in a list: len :: [Int] -> Int len [] = 0 len (x:xs) = 1 + len xs