Last active
November 6, 2018 08:01
-
-
Save cdsmith/f04f503e9336288f76ffab405c2aa04a to your computer and use it in GitHub Desktop.
This file contains 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
fixpoint :: Eq a => (a -> a) -> a -> a | |
fixpoint f x | |
| x == fx = fx | |
| otherwise = fixpoint f fx | |
where fx = f x | |
mySqrt :: Double -> Double | |
mySqrt n = fixpoint (\x -> (x + n/x) / 2) 1 | |
main :: IO () | |
main = print (mySqrt 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment