We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f95507a commit 4f048c9Copy full SHA for 4f048c9
Haskell Excercises & Code/MFAM - Practice/monad.hs
@@ -0,0 +1,23 @@
1
+module MonadicStuff where
2
+
3
+-- Checking udnerstanding of Monad instance for Maybe
4
+-- To write Monad. we need to write ApplICATIVE
5
+-- To write applicative we need Functor
6
+--import Data.Maybe
7
8
+instance Functor Maybe where
9
+ fmap f Nothing = Nothing
10
+ fmap f (Just x) = Just (f x)
11
12
+instance Applicative Maybe where
13
+ pure x = Just x
14
+ -- pure id <*> v = v
15
+ -- pure should not change the underlying values
16
+ Nothing <*> _ = Nothing
17
+ _ <*> Nothing = Nothing
18
+ Just f <*> Just n = Just (f n)
19
20
+instance Monad Maybe where
21
+ return = Just
22
+ Nothing >>= f = Nothing
23
+ (Just n) >>= f = f n
0 commit comments