Last active
August 29, 2015 14:17
-
-
Save LambdaP/edfe1b76d6028e85b63d to your computer and use it in GitHub Desktop.
Monad equivalence
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
{-# LANGUAGE UndecidableInstances, FlexibleInstances #-} | |
import Prelude hiding (return, join, (=<<)) | |
-- A Monad can be defined either with (>>=) + return, or with | |
-- fmap + join + return | |
class Return r where | |
return :: a -> r a | |
class Return m => MonadBind m where | |
(=<<) :: (a -> m b) -> m a -> m b | |
class (Return m, Functor m) => MonadJoin m where | |
join :: m (m a) -> m a | |
instance MonadBind m => Functor m where | |
fmap = (=<<) . (return .) | |
instance MonadBind m => MonadJoin m where | |
join = (=<<) id | |
instance MonadJoin m => MonadBind m where | |
(=<<) = (join .) . fmap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment