You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The right hand side can be viewed as a functional
$$e: (\mathbb{N} \rightarrow \mathbb{N}) \rightarrow (\mathbb{N} \rightarrow \mathbb{N})$$ $$e(f)\ =\quad x \mapsto\ f(x-2) + f(x-1)$$
Fixed point
$f$ is a fixed point for $e$ iff
$$e(f) = f$$
That is
$$f = e(f) = f(x-2) + f(x-1)$$
The fixed point combinator
$x$ is a fixed point for $f$ iff
$$f(x) = x$$
So a fixed point combinator must satisfy
$$f(\ fix(f)\ ) = fix(f)$$
We can use the left hand side as a definition
let rec fix f x = f (fix f) x
Coding without recursion
So, when we write
let rec fib x =
if x < 2 then x
else fib (x-2) + fib (x-1)
we are asking the compiler to compute the fixed point of
$$
e(f) = x \mapsto
\begin{cases}
\ 0 & ,\ x = 0 \\
\ 1 & ,\ x = 1 \\
\ f(x-2) + f(x-1) & ,\ x > 1
\end{cases}
$$
$$
e(f) = x \mapsto
\begin{cases}
\ 0 & ,\ x = 0 \\
\ 1 & ,\ x = 1 \\
\ f(x-2) + f(x-1) & ,\ x > 1
\end{cases}
$$
We can write this function explicitly
let fibU fibR x =
if x < 2 then x
else fibR (x-2) + fibR (x-1)