summaryrefslogtreecommitdiff
path: root/080_blog/00120_Lambda-Calculus-(Haskell)/index.md
diff options
context:
space:
mode:
Diffstat (limited to '080_blog/00120_Lambda-Calculus-(Haskell)/index.md')
-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