Skip to content

Instantly share code, notes, and snippets.

@beala
Created May 29, 2015 02:24
Show Gist options
  • Save beala/b2476482e5365645fa0f to your computer and use it in GitHub Desktop.
Save beala/b2476482e5365645fa0f to your computer and use it in GitHub Desktop.
FIxpoint combinator.
scala> def fix[A](f: (=> A) => A): A = f(fix(f))
fix: [A](f: (=> A) => A)A
scala> def fact(f: => (Int => Int))(n: Int): Int = if (n>0) n * f(n-1) else 1
fact: (f: => Int => Int)(n: Int)Int
scala> fix(fact)(10)
res19: Int = 3628800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment