summaryrefslogtreecommitdiff
path: root/080_blog/00120_Lambda-Calculus-(Haskell)
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2019-02-17 13:08:16 +0100
committerMiguel <m.i@gmx.at>2019-02-17 13:08:16 +0100
commit00447070772d74c33d099eb3d1097fa9a549cd57 (patch)
tree77034c5587a0558945948b57a022247de6d50272 /080_blog/00120_Lambda-Calculus-(Haskell)
first draft
Diffstat (limited to '080_blog/00120_Lambda-Calculus-(Haskell)')
-rw-r--r--080_blog/00120_Lambda-Calculus-(Haskell)/index.md38
1 files changed, 38 insertions, 0 deletions
diff --git a/080_blog/00120_Lambda-Calculus-(Haskell)/index.md b/080_blog/00120_Lambda-Calculus-(Haskell)/index.md
new file mode 100644
index 0000000..25c6b83
--- /dev/null
+++ b/080_blog/00120_Lambda-Calculus-(Haskell)/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