haskell - 匹配类型和单子(monad)。错误

标签 haskell

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) 类型。您可以使用 StateTErrorT 提供的函数将它们转换为底层 monad 的操作来解决此问题。

关于haskell - 匹配类型和单子(monad)。错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40324583/

相关文章:

Haskell,堆栈 : locate the executable

haskell - 存在类型歧义

list - Haskell Tuple 在无限列表上的解构在将 Tuple 作为参数解构时与使用 let 解构时的行为不同

haskell - 目录树的广度优先遍历不是懒惰的

haskell - fromInteger 如何工作?

haskell - F# 错误 : "Either make the arguments to ' it' explicit or, 如果您不打算将其通用,请添加类型注释。”

windows - Haskell Parsec 编译错误

haskell - 返回子类型集

Haskell 类依赖

haskell - 箭头完全等同于应用仿函数?