diff options
| author | Miguel <m.i@gmx.at> | 2019-02-19 16:42:05 +0100 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2019-02-19 16:42:05 +0100 |
| commit | 4b2d1a4571f44f8287888985aa8669b0151e7541 (patch) | |
| tree | 176142ae4e7d125f303c9e6bae149c1474d0d430 /080_blog/00040_Haskell-Projects/00120_Lambda-Calculus | |
| parent | 5c530e67256f8ecbd93336ba4e876acbba73f716 (diff) | |
v0.1
Diffstat (limited to '080_blog/00040_Haskell-Projects/00120_Lambda-Calculus')
| -rw-r--r-- | 080_blog/00040_Haskell-Projects/00120_Lambda-Calculus/index.md | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/080_blog/00040_Haskell-Projects/00120_Lambda-Calculus/index.md b/080_blog/00040_Haskell-Projects/00120_Lambda-Calculus/index.md new file mode 100644 index 0000000..25c6b83 --- /dev/null +++ b/080_blog/00040_Haskell-Projects/00120_Lambda-Calculus/index.md @@ -0,0 +1,38 @@ +Lambda Calculus +=============== + + May 2, 2018 + +Playing with Type Quantifiers and Haskell's Rank 2 Type Polymorphsim, +implementing Boolean logic from scratch. We use the conventional +definitions for `True` an `False` also known as Church booleans, after Alonzo Church, who +intruced them along Lambda Calculus in the 1930s [1]. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines} +{-# LANGUAGE Rank2Types #-} + +fTrue :: forall a. a->a->a +fTrue x y = x + +fFalse :: forall a. a->a->a +fFalse x y = y + +fAnd :: (forall a. a->a->a)->(forall a. a->a->a)->(forall a. a->a->a) +fAnd p q = p q p + +fOr :: (forall a. a->a->a)->(forall a. a->a->a)->(forall a. a->a->a) +fOr p q = p p q + +fNot :: (forall a. a->a->a)->(forall a. a->a->a) +fNot p = p fFalse fTrue + +ifThenElse :: (forall a. a->a->a)->(forall a. a->a->a) + ->(forall a. a->a->a)->(forall a. a->a->a) +ifThenElse p a b = p a b + +-- Example -- + +main = print $ (ifThenElse fFalse fFalse $ fAnd fTrue $ fNot fFalse) "T" "F" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + [1] https://en.wikipedia.org/wiki/Lambda_calculus |
