【发布时间】:2014-12-01 15:09:22
【问题描述】:
我正在测试一个 REST 服务器。我在 IO monad 中点击它并在State Db 中模拟它,其中Db 跟踪服务器的假定状态。以下函数应该运行两个版本并比较结果...
check :: (Eq a, MonadState d s) => s a -> IO a -> s (IO Bool)
-- or: check :: (Eq a, MonadState d s, MonadIO i) => s a -> i a -> s (i Bool)
check _ _ = (return.return) False -- for now
但是当我尝试使用这些最简单的功能时...
simReset :: State Db ()
realReset :: IO ()
reset :: StateT Db IO Bool
reset = check simReset realReset
我收到此错误:
Couldn't match expected type `Bool' with actual type `IO Bool'
Expected type: StateT Db IO Bool
Actual type: StateT Db IO (IO Bool)
In the return type of a call of `check'
In the expression: check simReset realReset
为什么?我该如何解决?
(这个话题从这里开始:Lift to fix the *inside* of a monad transformer stack)
【问题讨论】:
-
不能
s (IO Bool);simReset给你s ~ State,但是reset 的上下文使用StateT,这是不同的。您也不能在State上定义的函数内部使用来自StateT的状态;将simReset更改为通用MonadState或hoist。
标签: haskell monad-transformers