Last active
August 29, 2015 14:18
-
-
Save mikamix/da261e86a251ba954c4b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Monad where | |
import Prelude hiding (fmap, Functor, Monad) | |
class Functor f where | |
fmap :: (a -> b) -> f a -> f b | |
class Functor m => Applicative m where | |
pure :: a -> m a | |
ap :: m (a -> b) -> m a -> m b | |
class (Functor m, Applicative m) => Monad m where | |
(<$>) :: (a -> b) -> m a -> m b | |
f <$> a = bind (pure . f) a | |
(<*>) :: m (a -> b) -> m a -> m b | |
f <*> a = bind (<$> a) f | |
join :: m (m a) -> m a | |
join = bind id | |
bind :: (a -> m b) -> m a -> m b | |
bind f = join . fmap f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment