lundi 22 juillet 2013

Y U NO Y

After finally watching the 1986 SICP HP sessions, and many other videos building languages from nothing but lambdas, I can say I'm almost there for the Y-combinator. This choregraphy of bouncing `objects` (functions or whatever) is a thing of beauty. Wikipedia page on the matter includes some lazy functional example in Haskell :

dummy@x60s_GPT ~ [master *]
± % ghci

GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> let fix f = f (fix f)
Prelude> (fix (\f n -> if n == 0 then 1 else (f (n - 1)) * n)) 5
120
Prelude> -- amazed