我要通过国家单子here,我想要实现:实现状态monad时数据构造函数错误?
import Control.Monad.Reader
import Control.Monad.Writer
import Control.Monad.State
type Stack = [Int]
pop :: State Stack Int
pop = State $ (x : xs) -> (x, xs)
不过,我发现了以下错误:
"Data constructor not in scope:
State :: ([t0] -> (t0, [t0])) -> State Stack Int
Perhaps you meant one of these:
‘StateT’ (imported from Control.Monad.State),
variable ‘state’ (imported from Control.Monad.State)"
我在这里缺少一些基本的东西?
谢谢亚历克,非常清楚 - 我很高兴我不会在我年老时挑剔! –
[链接的教程已过时,而不是简化的事情。](http://hackage.haskell.org/package/mtl-1.0/docs/Control-Monad-State。html#t:State)有一段时间,人们担心与'Identity'相关的变换器相比直接定义相应的monad具有运行时成本,并且包含很多库(包括mtl)会同时发布monad及其变换器。最终代码复制/维护负担的论点反对这一点胜过了它的性能论证。 –