-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anastasios Valtinos
committed
Oct 6, 2022
1 parent
f95507a
commit 4f048c9
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |