summaryrefslogtreecommitdiff
path: root/applicative/h1.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-03-26 01:47:10 +0800
committerJoe Zhao <ztuowen@gmail.com>2015-03-26 01:47:10 +0800
commit36a645180f3ef13126c06b957d76c729f62d41fd (patch)
tree98658a7823bf3ccf3828f460dde85a694ba730a8 /applicative/h1.hs
parent934eda548d1f0260db095f2739b2211bd5157324 (diff)
downloadtypeclass-36a645180f3ef13126c06b957d76c729f62d41fd.tar.gz
typeclass-36a645180f3ef13126c06b957d76c729f62d41fd.tar.bz2
typeclass-36a645180f3ef13126c06b957d76c729f62d41fd.zip
applicative h1 h2
Diffstat (limited to 'applicative/h1.hs')
-rw-r--r--applicative/h1.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/applicative/h1.hs b/applicative/h1.hs
new file mode 100644
index 0000000..b13c33d
--- /dev/null
+++ b/applicative/h1.hs
@@ -0,0 +1,14 @@
+import Control.Applicative
+
+data MyMaybe a = MyNothing | MyJust a
+ deriving (Show)
+
+instance Functor MyMaybe where
+ fmap _ MyNothing = MyNothing
+ fmap f (MyJust x) = MyJust (f x)
+
+instance Applicative MyMaybe where
+ pure x = MyJust x
+ MyNothing <*> _ = MyNothing
+ _ <*> MyNothing = MyNothing
+ (MyJust f) <*> (MyJust g) = MyJust (f g)