Skip to content

Commit

Permalink
Checking Instance knowledge
Browse files Browse the repository at this point in the history
  • Loading branch information
Anastasios Valtinos committed Oct 6, 2022
1 parent f95507a commit 4f048c9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Haskell Excercises & Code/MFAM - Practice/monad.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module MonadicStuff where

-- Checking udnerstanding of Monad instance for Maybe
-- To write Monad. we need to write ApplICATIVE
-- To write applicative we need Functor
--import Data.Maybe

instance Functor Maybe where
fmap f Nothing = Nothing
fmap f (Just x) = Just (f x)

instance Applicative Maybe where
pure x = Just x
-- pure id <*> v = v
-- pure should not change the underlying values
Nothing <*> _ = Nothing
_ <*> Nothing = Nothing
Just f <*> Just n = Just (f n)

instance Monad Maybe where
return = Just
Nothing >>= f = Nothing
(Just n) >>= f = f n

0 comments on commit 4f048c9

Please sign in to comment.