summaryrefslogtreecommitdiff
path: root/00_blog/00040_Haskell/00120_Lambda-Calculus
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2019-03-17 18:14:32 +0100
committerMiguel <m.i@gmx.at>2019-03-17 18:14:32 +0100
commit0e4810dcfb132bf276a282e25b8523a4009ae08b (patch)
treedac6dce820f0a35d9ed7ea7676982a0f86fd0edb /00_blog/00040_Haskell/00120_Lambda-Calculus
parentad6411e9ec256b03f20b9195e25cb128fe02c628 (diff)
rename blog dir
Diffstat (limited to '00_blog/00040_Haskell/00120_Lambda-Calculus')
-rw-r--r--00_blog/00040_Haskell/00120_Lambda-Calculus/index.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/00_blog/00040_Haskell/00120_Lambda-Calculus/index.md b/00_blog/00040_Haskell/00120_Lambda-Calculus/index.md
new file mode 100644
index 0000000..b86950f
--- /dev/null
+++ b/00_blog/00040_Haskell/00120_Lambda-Calculus/index.md
@@ -0,0 +1,39 @@
+ May 2018
+Lambda Calculus
+===============
+
+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]](#ref).
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.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"
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+## Ref
+
+* [1] <https://en.wikipedia.org/wiki/Lambda_calculus>