Created
June 25, 2013 10:37
-
-
Save evandrix/5857533 to your computer and use it in GitHub Desktop.
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
data FreeF f a x = Pure a | Free (f x) | |
newtype FreeT f m a = | |
FreeT { runFreeT :: m (FreeF f a (FreeT f m a)) } | |
instance (Functor f, Monad m) => Monad (FreeT f m) where | |
return a = FreeT (return (Pure a)) | |
FreeT m >>= f = FreeT $ m >>= \v -> case v of | |
Pure a -> runFreeT (f a) | |
Free w -> return (Free (fmap (>>= f) w)) | |
instance MonadTrans (FreeT f) where | |
lift = FreeT . liftM Pure | |
liftF :: (Functor f, Monad m) => f r -> FreeT f m r | |
liftF x = FreeT (return (Free (fmap return x))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment