Haskell : how to get fix point of a function?
haskell
Solution
Technically it could be implemented as
fix f x = let x' = f x in if x == x' then x else fix f x'
You try and see that
fix (\x -> (x + 5) `div` 2) 12345
returns `5` and
print $ fix (\x -> (x + 3 / x) / 2) 12345
returns `1.7320508075688772`
Problem
A fix-point of a function f is a value x such that f(x)=x . Write a function fix that takes a function f and returns its fix-point. For example: the pseudocode is as follows: ``` f(x)= if (x=f(x)) return x else return f(f(x)) ``` How can I write it use Haskell?