"Monads允许程序员使用顺序构建块来构建计算",因此它允许我们组合一些计算.如果是这种情况,那么为什么以下代码无法运行?
import Control.Monad.Trans.State
gt :: State String String
gt = do
name <- get
putStrLn "HI" -- Here is the source of problem!
put "T"
return ("hh..." ++ name ++ "...!")
main= do
print $ execState gt "W.."
print $ evalState gt "W.."
Run Code Online (Sandbox Code Playgroud)
为什么我们不能将不同的函数放在monad中(如上例所示)?
为什么我们需要一个额外的层,即变换器来组合monad?