[Haskell-beginners] Questions about lambda calculus
Patrick LeBoutillier
patrick.leboutillier at gmail.com
Thu Nov 4 14:02:48 EDT 2010
Hi all,
I've been reading this article: http://perl.plover.com/lambda/tpj.html
in which the author talks about
the lambda calculus and uses examples in Perl (here's a link directly
to the code: http://perl.plover.com/lambda/lambda-brief.pl)
I'm a total newbie with respect to the lambda calculus.
fA = \x -> 'A'
fB = \x -> 'B'
x -=- y = (show $ x id) == (show $ y id)
I tried (naively) to port these examples to Haskell to play a bit with them:
fTRUE = \a -> \b -> a
fFALSE = \a -> \b -> b
fIF = \b -> \x -> \y -> b x y
fPAIR = \a -> \b -> \f -> f a b
fFIRST = \p -> p fTRUE
fSECOND = \p -> p fFALSE
fZERO = fPAIR fTRUE fTRUE
fSUCC = \x -> fPAIR fFALSE x
fIS_ZERO = \x -> fFIRST x
fPRED = \x -> fSECOND x
fONE = fSUCC fZERO
fTWO = fSUCC fONE
fADD = \m -> (\n -> fIF (fIS_ZERO m) n (fADD (fPRED m) (fSUCC n)))
but I couldn't get fADD to compile:
Occurs check: cannot construct the infinite type:
t = (t1 -> t1 -> t1) -> t
Probable cause: `fADD' is applied to too many arguments
In the third argument of `fIF', namely `(fADD (fPRED m) (fSUCC n))'
In the expression: fIF (fIS_ZERO m) n (fADD (fPRED m) (fSUCC n))
I think its because in these Perl examples all functions are treated as being
of the same type (number or type of args doesn't matter), but this is
not the case in Haskell.
Is there any way to create code similar to this in Haskell?
Thanks,
Patrick
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
More information about the Beginners
mailing list