Jump to content

Y combinator: Difference between revisions

Line 2,899:
 
=={{header|F Sharp|F#}}==
In spite of everything that follows I am going to go with this.
<syntaxhighlight lang="fsharp">
// Y combinator. Nigel Galloway: March 5th., 2024
type Y<'T> = { eval: Y<'T> -> ('T -> 'T) }
let Y n g=let l = { eval = fun l -> fun x -> (n (l.eval l)) x } in (l.eval l) g
let fibonacci=function 0->1 |x->let fibonacci f= function 0->0 |1->1 |x->f(x - 1) + f(x - 2) in Y fibonacci x
printfn "%d" (fibonacci 10)
</syntaxhighlight>
{{output}}
<pre>
55
</pre>
<syntaxhighlight lang="fsharp">type 'a mu = Roll of ('a mu -> 'a) // ' fixes ease syntax colouring confusion with
2,172

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.