Created
July 14, 2015 05:36
-
-
Save etscrivner/bc907c63d7303fe32def to your computer and use it in GitHub Desktop.
Haskell lazy evaluated sqrt approximations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| average :: Float -> Float -> Float | |
| average x y = (x + y) / 2 | |
| sqrtImprove :: Float -> Float -> Float | |
| sqrtImprove guess x = average guess (x / guess) | |
| sqrtStream :: Float -> [Float] | |
| sqrtStream x = 1.0 : (map (\guess -> (sqrtImprove guess x)) (sqrtStream x)) | |
| main :: IO () | |
| main = print (take 5 (sqrtStream 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment