Y combinator: Difference between revisions

m
 
(5 intermediate revisions by 3 users not shown)
Line 988:
test("fac")
test("fib")</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
This BLC program outputs 6!, as computed with the Y combinator, in unary (generated from https://github.com/tromp/AIT/blob/master/rosetta/facY.lam) :
 
<pre>11 c2 a3 40 b0 bf 65 ee 05 7c 0c ef 18 89 70 39 d0 39 ce 81 6e c0 3c e8 31</pre>
 
=={{header|BlitzMax}}==
Line 2,894 ⟶ 2,899:
 
=={{header|F Sharp|F#}}==
===March 2024===
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
let factorial n=let factorial f=function 0->1 |x->x*f(x-1) in Y factorial n
printfn "fibonacci 10=%d\nfactorial 5=%d" (fibonacci 10) (factorial 5)
</syntaxhighlight>
{{output}}
<pre>
fibonacci 10=55
factorial 5=120
</pre>
===Pre March 2024===
<syntaxhighlight lang="fsharp">type 'a mu = Roll of ('a mu -> 'a) // ' fixes ease syntax colouring confusion with
Line 4,907 ⟶ 4,928:
#'
 
fixp.Y <- \ (f) (\ (x) (x) (x)) (\ (y) (f) ((y) (y))) # y-combinator.
fixp.Z <- \ (f) (\ (x) (x) (x)) (\ (y) (f) (\ (...) (y) (y) (...))) # z-combinator also.
</syntaxhighlight>
 
Line 4,931 ⟶ 4,952:
</syntaxhighlight>
 
You can verify these codes by [https://shinylive.io/r/editor/#code=NobwRAdghgtgpmAXGAZgSwB5wCYAcD2aEALgHQBOYANGAMb4lwlJgDEA5AAQCanAvJ0DdwClIAKQQGdSEiQEpxGUilEYMs2QB0IHTgC1+QkeKkz5gxcsEAvMatlX1WnVq3oMuUrwA8AWk4aNTlEUWSCAoLUI0JV1MMDRAE9okKDE6KTY1k4En3oYACMiKGJ8clJXTA99X394lNFwmKio6MakoPrG0m703qDu0nVQrKtcQkeKkz5gxcsEAvMatlX1WnVq3oMuUrwA8AWk4aNTlEUWSCAoLUI0JV1MMDRAE9okKDE6KTY1k4En3oYACMiKGJ8cldMD31ff3iU0XCYqKjohqSguobSLvSeoK7SdVCsq1z8AqKSsognLgBXCTgXCBQoWlIEzmq3D1562tCGiFC0FCCILwAmUIBGTjgAGwXOCAAqZQgfa8dl1fXRAE4hpxgNcALqcADMADYLgAOWEABiW6Hy602fm2nji7QO8SOnBOZ02Ai+zzujzgnHen1CAGoqaIPldNMs0KiEgCgSDwRCACxLVy-AKikvJOKAAbCXxyiCcuAFcJOBcIFChaUgTOGrcPXga60MaIULQUIIgvACZQgEZOOHm4TggAKmUIH2ejm2u32ogAnMNOMBngBdTgAZgAbA8ABwogAMW3QKzoqkVUj6PY4mpnY6nRmXG7kp6valfFkrNZWTmcLLcyEw+X2hz8x08cQ6F3iV04NzuhwEgKFI6as1HCrZiiUNFKHWVErwk0IQJWU1V0hlM74o0hawE64FgyH8iBgAC+bw+nD+ANCAGoGaJ-k9NNs0DiEuDIdC4fCACxbVwgqx4hmVUj6M7E2p3a63dmPF50jZfX7splcnZ7Kz8zhZQUI5FozHLbk4yVHGVyxopS7KyleamhCAaz6Mmmsxmcio2o0m2EI0UQMAAXxhQAoKAA here]
 
=={{header|Racket}}==
2,172

edits