type C = StateT Int (ErrorT String IO)
main :: C ()
main = do
args <- liftIO $ getArgs
case args of
[] -> liftIO $ putStrLn "E"
(p:ps) -> s "d"
s :: String -> C ()
我遇到错误:
Couldn't match type ‘Control.Monad.Trans.State.Lazy.StateT
Int
(Control.Monad.Trans.Error.ErrorT String IO)
()’
with ‘IO t0’
Expected type: IO t0
Actual type: C ()
In the expression: main
When checking the type of the IO action ‘main’
我不明白为什么会出现错误以及如何修复它。请帮忙。
最佳答案
对于某些 a
,
main
必须是 IO a
类型(通常但不一定是 ()
)。它不能是 StateT Int (ErrorT String IO)
类型。您可以使用 StateT
和 ErrorT
提供的函数将它们转换为底层 monad 的操作来解决此问题。
关于haskell - 匹配类型和单子(monad)。错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40324583/