小编Sim*_*Guy的帖子

MonadBaseControl IO ... StateT实现

我试图弄清楚如何为类型Foo 实现MonadBaseControl实例,这是一个围绕StateT实例的newtype包装器.你会认为它会像这样实现,但似乎并非如此.我假设状态片在这里引起了问题,所以有没有办法放弃它?

码:

newtype Foo a = Foo { unFoo :: StateT Int IO a } 
                deriving (Monad, Applicative, Functor, MonadBase IO)

instance MonadBaseControl IO Foo where
   type StM Foo a = a 
   liftBaseWith f = Foo $ liftBaseWith $ \q -> f (q . unFoo)
   restoreM = Foo . restoreM 
Run Code Online (Sandbox Code Playgroud)

错误:

 Couldn't match type ‘a’ with ‘(a, Int)’
 ‘a’ is a rigid type variable bound by
 the type signature for restoreM :: StM Foo a …
Run Code Online (Sandbox Code Playgroud)

monads haskell monad-transformers

4
推荐指数
1
解决办法
207
查看次数

标签 统计

haskell ×1

monad-transformers ×1

monads ×1