11 Nov
2010
11 Nov
'10
1:44 a.m.
On Wed, Nov 10, 2010 at 3:36 PM, Ryan Ingram <ryani.spam@gmail.com> wrote:
Max has a good solution, but another solution is to embed an untyped lambda calculus into Haskell
-- "atom" is just used for output during testing data U = Atom Int | F (U -> U)
instance Show U where show (Atom s) = s show (F _) = "<function>"
-- function application F f $$ x = f x infixl 9 $$
fTrue = F $ \x -> F $ \y -> x fFalse = F $ \x -> F $ \y -> y
fIf = F $ \b -> F $ \x -> F $ \y -> b $$ x $$ y
this also has the "benefit" of looking as perlish as the original example, if you know what I mean... ;)