3 ms·
While we're showing off pointless interpreters, here's a simple currying lazy lambda-calculus-like language with pattern-matching-based choice: http://hpaste.or
by chrisdone 16y ago
While we're showing off pointless interpreters, here's a simple currying lazy lambda-calculus-like language with pattern-matching-based choice: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=24800 http://hpaste.org/fastcgi/hpaste.fcgi/view?id=24800
It achieves recursive definitions using fix (teh Y combinator!! \f.(\x.f (x x)) (\x.f (x x))). Binding variables is done with lambda abstractions. Pattern matching is done with (foo).
fix (\a.\(0) n.add n 1;m n.(\(true).a (sub m 1) 1;(false).a (sub m 1) (a m (sub n 1))) (eq n 0)) 3 2
It works out the Ackermann of 3 and 2 (29) in about the same time normal Haskell does in GHCi. Isn't it just a joy to read?