From 36a645180f3ef13126c06b957d76c729f62d41fd Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Thu, 26 Mar 2015 01:47:10 +0800 Subject: applicative h1 h2 --- applicative/h1.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 applicative/h1.hs (limited to 'applicative/h1.hs') 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) -- cgit v1.2.3-70-g09d2