Last active
July 23, 2017 10:10
-
-
Save rxwei/b3e0b644cae8f15fc8da69cea9776bd1 to your computer and use it in GitHub Desktop.
Staged Y combinator with NNKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Y combinator | |
func fix<D, R>( | |
_ f: @escaping (Rep<(D) -> R>) -> Rep<(D) -> R>) -> Rep<(D) -> R> { | |
return lambda { d in f(fix(f))[d] } | |
} | |
let fac: Rep<(Int) -> Int> = fix { f in | |
lambda { (n: Rep<Int>) in | |
.if(n == 0, then: ^1, else: n * f[n - 1]) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment