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.

Thanks,

Patrick

---------- Forwarded message ----------
From: Patrick LeBoutillier <patrick.leboutillier at gmail.com>
Date: Thu, Nov 4, 2010 at 2:02 PM

Hi all,

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. 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

Is there any way to create code similar to this in Haskell?

Thanks,

Patrick

--
=====================
Patrick LeBoutillier