不推导MonadException实例 [英] MonadException instance is not deduced
本文介绍了不推导MonadException实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
没有用于(MonadException Ti)的实例$在代码示例中使用`getInputLine'
引起的$ b $
module Foo其中
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
Nothing - > return()
只需输入 - >提升(动作输入)>>现在, System.Console.Haskeline.MonadException $ c $> c>定义
MonadException IO
(MonadIO(StateT sm),MonadException m)=> MonadException(StateT sm)
和 Control.Monad.IO.Class :
MonadIO IO
MonadIO m => MonadIO(StateT sm)
所以,它不应该推导出 Ti
自动地吗?
解决方案 Lazy状态转换器没有实例,只是严格的。使用导入Control.Monad.State.Strict
。
Maybe I'm doing something stupid here, but I'm getting:
No instance for (MonadException Ti)
arising from a use of `getInputLine'
in the code sample:
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
Now, System.Console.Haskeline.MonadException
defines
MonadException IO
(MonadIO (StateT s m), MonadException m) => MonadException (StateT s m)
and Control.Monad.IO.Class
:
MonadIO IO
MonadIO m => MonadIO (StateT s m)
So, shouldn't it deduce the instance for Ti
automatically?
解决方案 There is no instance for the Lazy state transformer, just the strict one. Use import Control.Monad.State.Strict
.
这篇关于不推导MonadException实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文