From 80a5790a56043c8bf8dd3e01d5a9d6b776a13f55 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Fri, 26 Dec 2014 22:13:59 +0530
Subject: [PATCH] scratch pad notes on applicatives

---
 misc/applicatives.hs | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 misc/applicatives.hs

diff --git a/misc/applicatives.hs b/misc/applicatives.hs
new file mode 100644
index 0000000..abf9231
--- /dev/null
+++ b/misc/applicatives.hs
@@ -0,0 +1,30 @@
+liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
+liftA2 h fa fb = (h `fmap` fa) <*> fb
+
+-- In fact, this pattern is so common that Control.Applicative defines (<$>) as a synonym for fmap,
+
+(<$>) :: Functor f => (a -> b) -> f a -> f b
+(<$>) = fmap
+
+liftA2 h fa fb = h <$> fa <*> fb
+
+{-|
+
+h -> (a -> b -> c)
+
+-- (a -> b -> c) -> f a -> f (b -> c)
+h <$> fa = hfa
+
+-- (<*>) :: f (a -> b) -> f a -> f b
+-- hfa <*> f b
+-- f (b -> c) -> f b -> f c
+
+-- Applicative law
+-- f `fmap` x === pure f <*> x
+
+-- lhs = (a -> b) `fmap` f a gives a value of type f b
+-- rhs = pure f.
+--     f  has the type (a -> b), so pure f has the type f (a -> b)
+--   pure f <*> x => f (a -> b> <*> f a => f b
+
+-}
\ No newline at end of file
-- 
2.45.2