Hello everyone I'm trying to implement the higher-order function fix, which computes an attractive fixed point of an arbitrary function f :: a -> a
from an initial point x
. That is, a fixed point of the form fᴷ(x)
for a given f
and x
.
-- CONTRACT
fix :: Eq a => (a -> a) -> a -> a
-- DEFINITION [TODO: Implement fix]
fix f x = ?
My current attempt is:
fix f x | f x == x = x
| otherwise = fix f x
where x = f x
Note: Your function will not terminate if the function does not converge from the starting point. can someone help me please ? I tried but it didn't return anything