Acid-state:用于更新的MonadState实例 [英] Acid-state: MonadState instance for Update
问题描述
我正在尝试 acid-state
。 文件表示 Update st
是 MonadState st
的一个实例。我尝试了不同的东西,但我的编译器不想看到:(我从 HelloWorld.hs >。 it / acid-state / examples /rel =nofollow> examples ,但得到同样的问题:
HelloWorld.hs:26:7:
由于使用'put'
而没有(MonadState
HelloWorldState(更新HelloWorldState))
的实例可能的修正:
为
添加一个实例声明(MonadState HelloWorldState(更新HelloWorldState))
在表达式中:put(HelloWorldState newValue)
在`writeState'等式中:
writeState newValue = put(HelloWorldState newValue)
HelloWorld.hs:29:43:
没有用于(MonadReader
HelloWorldState(查询HelloWorldState))
的实例,询问'
可能的修正:
为
添加实例声明(MonadReader HelloWorldSt ate(Query HelloWorldState))
在'do'块的标记中:HelloWorldState字符串< - 问
在表达式中:
do {HelloWorldState string< - ask;
返回字符串}
在`queryState'的等式中:
queryState
= do {HelloWorldState string< - ask;
返回字符串}
我做错了什么?如何使它工作?
我使用
acid-state-0.6.4
,
ghc-7.4.2
,
debian-6.0.5
(amd64) p>
感谢,
Yuras
添加:
看起来像它在ghc-7.4.1中工作,在ghc-7.4.2中不起作用。任何人都可以编译?
我尝试重新安装酸性状态,但没有帮助。无论是ghc-7.4.2中的一个bug还是我的环境ID都坏了。
好的,我终于解决了它。
问题在于安装了两个不同的 mtl
版本。
有趣的部分是我如何得到它:)
Prelude Data.Acid Control.Monad.State> :我更新
newtype更新st a
= acid-state-0.6.4:Data.Acid.Common.Update {acid-state-0.6.4:Data.Acid.Common.unUpdate :: transformers -0.2.2.0:Control.Monad.Trans.State.Lazy.State
st a}
- 在`acid-state-0.6.4:Data.Acid.Common'中定义
实例Monad(更新st)
- 定义于`acid-state-0.6.4:Data.Acid.Common'
实例Functor(更新st)
- 定义于`acid- state-0.6.4:Data.Acid.Common'
Prelude Data.Acid Control.Monad.State>
Control.Monad.State
reexports State
,但你可以看到ghci仍显示变形金刚-0.2.2.0:Control.Monad.Trans.State.Lazy.State
完全限定。
I'm trying acid-state
. The documentation states that Update st
is an instance of MonadState st
. I tried different things, but my compiler doesn't want to see that :( I tried the HelloWorld.hs
from examples, but got the same issue:
HelloWorld.hs:26:7:
No instance for (MonadState
HelloWorldState (Update HelloWorldState))
arising from a use of `put'
Possible fix:
add an instance declaration for
(MonadState HelloWorldState (Update HelloWorldState))
In the expression: put (HelloWorldState newValue)
In an equation for `writeState':
writeState newValue = put (HelloWorldState newValue)
HelloWorld.hs:29:43:
No instance for (MonadReader
HelloWorldState (Query HelloWorldState))
arising from a use of `ask'
Possible fix:
add an instance declaration for
(MonadReader HelloWorldState (Query HelloWorldState))
In a stmt of a 'do' block: HelloWorldState string <- ask
In the expression:
do { HelloWorldState string <- ask;
return string }
In an equation for `queryState':
queryState
= do { HelloWorldState string <- ask;
return string }
What I'm doing wrong? How to make it work?
I'm using
acid-state-0.6.4
,
ghc-7.4.2
,
debian-6.0.5
(amd64)
Thanks, Yuras
ADDED: Looks like it works in ghc-7.4.1 and doesn't work in ghc-7.4.2. Could anybody both compilers?
I tried reinstalling acid-state, but it didn't help. Either a bug in ghc-7.4.2 or my environment id broken.
Ok, I finally solved it.
The issue was with two different mtl
versions installed. Hiding the wrong one fixed everything.
The interesting part is how I got it :)
Prelude Data.Acid Control.Monad.State> :i Update
newtype Update st a
= acid-state-0.6.4:Data.Acid.Common.Update {acid-state-0.6.4:Data.Acid.Common.unUpdate :: transformers-0.2.2.0:Control.Monad.Trans.State.Lazy.State
st a}
-- Defined in `acid-state-0.6.4:Data.Acid.Common'
instance Monad (Update st)
-- Defined in `acid-state-0.6.4:Data.Acid.Common'
instance Functor (Update st)
-- Defined in `acid-state-0.6.4:Data.Acid.Common'
Prelude Data.Acid Control.Monad.State>
Control.Monad.State
reexports State
, but you can see that ghci still shows transformers-0.2.2.0:Control.Monad.Trans.State.Lazy.State
fully qualified.
这篇关于Acid-state:用于更新的MonadState实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!