Skip to content

Instantly share code, notes, and snippets.

@haileys
Created September 12, 2017 15:40
Show Gist options
  • Save haileys/b0b852a8a7b3a3968e3d073f64fe8c72 to your computer and use it in GitHub Desktop.
Save haileys/b0b852a8a7b3a3968e3d073f64fe8c72 to your computer and use it in GitHub Desktop.
import Control.Monad
import Data.Monoid
data MState s a = MState s a
instance Monoid s => Functor (MState s) where
fmap f (MState st x) = MState st (f x)
instance Monoid s => Applicative (MState s) where
pure = return
(<*>) = ap
instance Monoid s => Monad (MState s) where
return x = MState mempty x
(>>=) (MState st x) f = MState (mappend st st') x'
where (MState st' x') = f x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment