Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,9 @@
let fib: Int -> Int = {
func f(n: Int) -> Int {
assert(n >= 0, "fib: no negative numbers")
return n < 2 ? 1 : f(n-1) + f(n-2)
}
return f
}()
print(fib(8))

View file

@ -0,0 +1,10 @@
let fib: Int -> Int = {
var f: (Int -> Int)!
f = { n in
assert(n >= 0, "fib: no negative numbers")
return n < 2 ? 1 : f(n-1) + f(n-2)
}
return f
}()
println(fib(8))

View file

@ -0,0 +1,15 @@
struct RecursiveFunc<F> {
let o : RecursiveFunc<F> -> F
}
func y<A, B>(f: (A -> B) -> A -> B) -> A -> B {
let r = RecursiveFunc<A -> B> { w in f { w.o(w)($0) } }
return r.o(r)
}
func fib(n: Int) -> Int {
assert(n >= 0, "fib: no negative numbers")
return y {f in {n in n < 2 ? 1 : f(n-1) + f(n-2)}} (n)
}
println(fib(8))