我只是好奇为什么这段代码不能编译。为什么要求 m 是 MonadReader ConnState?:
newtype Netbeans m a = Netbeans { unNetbeans :: ReaderT ConnState m a }
deriving (Monad, Functor, Applicative, MonadIO, MonadTrans)
instance Monad m => MonadReader ConnState (Netbeans m) where
ask = Netbeans $ ask
local f x = Netbeans $ mapReaderT (local f) (unNetbeans x)
错误信息如下(第 88 行与本地函数定义一致):
src/Vim/Netbeans.hs:88:40:
Could not deduce (MonadReader ConnState m)
arising from a use of `local'
from the context (Monad m)
bound by the instance declaration at src/Vim/Netbeans.hs:86:10-54
Possible fix:
add (MonadReader ConnState m) to the context of
the type signature for
local :: (ConnState -> ConnState) -> Netbeans m a -> Netbeans m a
or the instance declaration
or add an instance declaration for (MonadReader ConnState m)
In the first argument of `mapReaderT', namely `(local f)'
In the second argument of `($)', namely
`mapReaderT (local f) (unNetbeans x)'
In the expression: Netbeans $ mapReaderT (local f) (unNetbeans x)
提前致谢。