Skip to content

Instantly share code, notes, and snippets.

@kuenishi
Created March 24, 2010 16:12
Show Gist options
  • Save kuenishi/342443 to your computer and use it in GitHub Desktop.
Save kuenishi/342443 to your computer and use it in GitHub Desktop.
-module(yc). % Y Combinator
-compile(export_all).
-spec f( Fact::fun( (integer())-> integer() ) )-> fun((integer())-> integer()).
f(Fact)-> fun (1)-> 1;(X)-> X*Fact(X-1) end.
-spec y( F::fun( (fun((TypeA)-> TypeB)) -> fun((TypeA)-> TypeB) ))-> fun((TypeA)->TypeB).
y(F)-> fun(X)-> (F( y(F)))(X) end.
-spec do(integer())-> integer().
do(N)-> (y(fun f/1))(N).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment