不推断出MonadException实例

时间:2013-06-05 15:32:48

标签: haskell

也许我在这里做了些蠢事,但我得到了:

No instance for (MonadException Ti)
  arising from a use of `getInputLine'
代码示例中的

module Foo where
import System.Console.Haskeline
import System.Console.Haskeline.MonadException
import Control.Monad.State
import Control.Monad.IO.Class

type Ti = StateT Int IO

action :: String -> Ti ()
action s = do
    n <- get
    lift $ putStrLn $ show n ++ ": " ++ s

repl :: InputT Ti ()
repl = do
    minput <- getInputLine "?"
    case minput of
        Nothing    -> return ()
        Just input -> lift (action input) >> repl

现在,System.Console.Haskeline.MonadException定义了

MonadException IO
(MonadIO (StateT s m), MonadException m) => MonadException (StateT s m)

Control.Monad.IO.Class

MonadIO IO
MonadIO m => MonadIO (StateT s m)

那么,它不应该自动推断Ti的实例吗?

1 个答案:

答案 0 :(得分:9)

Lazy状态变换器没有实例,只有严格的变压器。使用import Control.Monad.State.Strict