Created
May 29, 2012 14:55
-
-
Save notyy/2828885 to your computer and use it in GitHub Desktop.
Writer with State
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
import Control.Monad | |
import Control.Monad.State | |
import Control.Monad.Writer | |
type User = String | |
type Log = [String] | |
login :: String -> State [User] () | |
login u = do | |
modify (u:) | |
doSomeLogin :: State [User] () | |
doSomeLogin = do | |
login "notyy" | |
login "bad guy" | |
login "kia" | |
loginWL :: String -> Writer Log () | |
loginWL u = do | |
tell $ [u ++ " logged in"] | |
doSomeLoginWL = do | |
loginWL "notyy" | |
loginWL "bad guy" | |
loginWL "kia" | |
------------------------------can runState or runWriter, but how to combine them together? | |
*Main> runState doSomeLogin [] | |
((),["kia","bad guy","notyy"]) | |
*Main> runWriter doSomeLoginWL | |
((),["notyy logged in","bad guy logged in","kia logged in"]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment