Created
October 30, 2012 11:06
-
-
Save miguel-negrao/3979631 to your computer and use it in GitHub Desktop.
Monad Transformers hello world
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
module Main where | |
import Control.Monad.State | |
import Control.Monad.Trans | |
import Control.Monad.Maybe | |
import Control.Monad.Reader | |
import Control.Monad.Writer | |
type X = ReaderT String (WriterT [String] (StateT Int Maybe)) Int | |
main:: IO() | |
main = print $ runStateT (runWriterT (runReaderT m1 "hello world")) 0 | |
m1 :: X | |
m1 = do | |
put 32 | |
(lift.lift.lift) Nothing | |
m2 :: X | |
m2 = do | |
x <- ask | |
put 32 | |
return 50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment