小编4xx*_*4xx的帖子

Monad vs Monad变形金刚

"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?

monads haskell monad-transformers

4
推荐指数
1
解决办法
189
查看次数

标签 统计

haskell ×1

monad-transformers ×1

monads ×1