Skip to content

Instantly share code, notes, and snippets.

@cdsmith
Last active November 6, 2018 08:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdsmith/f04f503e9336288f76ffab405c2aa04a to your computer and use it in GitHub Desktop.
Save cdsmith/f04f503e9336288f76ffab405c2aa04a to your computer and use it in GitHub Desktop.
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