On Sun, Dec 7, 2008 at 3:05 AM, Hans Aberg <[EMAIL PROTECTED]> wrote:

> One can define operators
>  a ^ b := b(a)          -- Application in inverse.
>  (a * b)(x) := b(a(x))  -- Function composition in inverse.
>  (a + b)(x) := a(x) * b(x)
>  O(x) := I              -- Constant function returning identity.
>  I(x) := x              -- Identity.
> and use them to define lambda calculus (suffices with the first four;
> Church reverses the order of "*").


The simple elegance of writing this encoding just increased my already
infinite love of Haskell by another cardinality.

a .^ b = b a
(a .* b) x = b (a x)
(a .+ b) x = a x .* b x
o x = i
i x = x

toNat x = x (+1) 0
fromNat n = foldr (.) id . replicate n

Luke
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to