也许我在这里做一些愚蠢的事情,但我得到:
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
自动推断实例吗?