Last active
December 23, 2015 11:59
-
-
Save virtualsafety/6632668 to your computer and use it in GitHub Desktop.
http://blog.sigfpe.com/2006/05/grok-haskell-monad-transformers.html
第3个例子的signature搞了两天才根据下面的问题弄正确
http://stackoverflow.com/questions/15625867/why-dont-you-need-to-use-lift-when-interacting-with-a-nested-statet-monadt-in?rq=1
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.State | |
import Control.Monad.Identity | |
import Data.Char(toUpper) | |
test1 :: State Int (Int,Int) | |
test1 = do | |
a <- get | |
modify (+1) | |
b <- get | |
return (a,b) | |
test2 :: State [Char] ([Char],[Char]) | |
test2 = do | |
a <- get | |
modify (++"1") | |
b <- get | |
return (a,b) | |
--let go1 = evalState test1 0 | |
--let go2 = evalState test2 "0" | |
test3 :: StateT Int ( StateT [Char] Identity ) (Int, [Char]) | |
test3 = do | |
modify (+1) | |
lift $ modify (++ "1") | |
a <- get | |
b <- lift get | |
return (a,b) | |
--let go3 = runIdentity $ evalStateT (evalStateT test3 0) "0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment