Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
7
Task/Y-combinator/Scala/y-combinator-1.scala
Normal file
7
Task/Y-combinator/Scala/y-combinator-1.scala
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def Y[A, B](f: (A => B) => (A => B)): A => B = {
|
||||
case class W(wf: W => (A => B)) {
|
||||
def apply(w: W): A => B = wf(w)
|
||||
}
|
||||
val g: W => (A => B) = w => f(w(w))(_)
|
||||
g(W(g))
|
||||
}
|
||||
5
Task/Y-combinator/Scala/y-combinator-2.scala
Normal file
5
Task/Y-combinator/Scala/y-combinator-2.scala
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
val fac: Int => Int = Y[Int, Int](f => i => if (i <= 0) 1 else f(i - 1) * i)
|
||||
fac(6) //> res0: Int = 720
|
||||
|
||||
val fib: Int => Int = Y[Int, Int](f => i => if (i < 2) i else f(i - 1) + f(i - 2))
|
||||
fib(6) //> res1: Int = 8
|
||||
Loading…
Add table
Add a link
Reference in a new issue