Skip to content

Instantly share code, notes, and snippets.

@timyates
Created March 6, 2013 14:16
Show Gist options
  • Save timyates/5099575 to your computer and use it in GitHub Desktop.
Save timyates/5099575 to your computer and use it in GitHub Desktop.
Y combinator factorial in Groovy
fact_improver = { partial ->
{ BigInteger n ->
n == 0 ? 1 : n * partial( n - 1 )
}
}
y = { improver ->
{ gen -> { BigInteger n -> improver( gen( gen ) )( n ) } } { gen ->
{ BigInteger n -> improver( gen( gen ) )( n ) } }
}
fx = y( fact_improver )
fx( 5 )
@timyates
Copy link
Author

timyates commented Mar 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment