Skip to content

Instantly share code, notes, and snippets.

@pardom
Created May 26, 2020 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pardom/f797196f3d9963fc16f29daf4798cdfa to your computer and use it in GitHub Desktop.
Save pardom/f797196f3d9963fc16f29daf4798cdfa to your computer and use it in GitHub Desktop.
class FunR<A, B>(private val f: (FunR<A, B>) -> (A) -> B) {
operator fun invoke(a: FunR<A, B>): (A) -> B = f(a)
}
fun <A, B> y(f: ((A) -> B) -> (A) -> B): (A) -> B =
FunR<A, B> { r -> f { a -> r(r)(a) } }.let { g -> g(g) }
val fac = y { f: (Int) -> Int ->
{ x ->
if (x <= 1) 1 else x * f(x - 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment