I have an OCaml function for finding fixed points:
>> let rec fix f x =
let x' = f x in
if x = x' then x else fix f x';;
(system message) val fix : ('a -> 'a) -> 'a -> 'a = <fun>
The question is, I don't understand how it works when I type:
>> let cubed x = x*x*x;;
(system message) val cubed : int -> int = <fun>
>> fix cubed 2;;
(system message) - : int = 0
In my understanding, fix cubed 2
will go into an infinite loop of fix cubed 2*2*2
, fix cubed (2*2*2)*(2*2*2)*(2*2*2)
and so on. How does this function correctly finds the fixed point 0
?