[Haskell-cafe] Fwd: Questions about lambda calculus

Patrick LeBoutillier patrick.leboutillier at gmail.com
Wed Nov 10 07:49:57 EST 2010

Hi all,

Sorry for cross-posting this, but I didn't get anything on the
beginners list so I thought I'd give it a try here.



---------- Forwarded message ----------
From: Patrick LeBoutillier <patrick.leboutillier at gmail.com>
Date: Thu, Nov 4, 2010 at 2:02 PM
Subject: Questions about lambda calculus
To: beginners <beginners at haskell.org>

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:

I'm a total newbie with respect to the lambda calculus. 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

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?



Patrick LeBoutillier
Rosemère, Québec, Canada

More information about the Haskell-Cafe mailing list