StateT和WX gui共存
通常的wxHaskell程序看起来像
main = do
run gui
gui = do
....
....
gui必须有类型IO a
,运行有类型IO a -> IO()
,在run
中还有一些初始化例程。
我尝试执行以下操作:
data AppGlobals = AG { ... some data ... }
type MApp a = StateT AppGlobals IO a
但在这种情况下,gui 必须具有类型 gui :: MApp AppGlobals
。由于它的类型,不可能使用通常的 IO monad 语法,我的意思是每次执行 IO 操作时我都必须使用 liftIO 。
在 wxHaskell 中是否有方便使用 State monad 的可能性?手动将状态传递给每个事件处理程序不太方便。
usual wxHaskell program looks like
main = do
run gui
gui = do
....
....
gui must have type IO a
, run has type IO a -> IO ()
, also there is some initialization routines in run
.
I'm tring to do following:
data AppGlobals = AG { ... some data ... }
type MApp a = StateT AppGlobals IO a
But in this case gui must have type gui :: MApp AppGlobals
. Due to it's type it becomes impossible to use usual IO monad syntax, I mean Ihave to use liftIO
every time I performing IO action.
Is there Any convinient possibility to use State monad in wxHaskell? It's not very convinient to pass state to each event handler manually.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我读过和写过的 wxHaskell 程序只是将状态推入变量中。
http://wxhaskell.sourceforge.net/doc/Graphics-UI- WX-变量.html
这是一个很好的概述:
http://legacy.cs.uu.nl/daan/download/ paper/wxhaskell.pdf
他们使用启动而不是运行。
The wxHaskell programs I've read and written just shove the state into variables.
http://wxhaskell.sourceforge.net/doc/Graphics-UI-WX-Variable.html
Here's a good overview:
http://legacy.cs.uu.nl/daan/download/papers/wxhaskell.pdf
And they use start rather than run.
理论上是可行的,但我发现它在实践中很麻烦,就像你一样。我自己的 wxHaskell 代码通常看起来像我在引用的博客文章中描述的那样:
http://wewantarock.wordpress.com/2010/01/11/custom-controls-in-wxhaskell-part-3/
您可以按照 ja 的建议使用 wxHaskell 变量同样的目的,尽管我更喜欢在博客中使用的更明确的风格。
It's possible in theory, but I've found it to be cumbersome in practice, as you did. My own wxHaskell code usually looks something like I described in the referenced blog article:
http://wewantarock.wordpress.com/2010/01/11/custom-controls-in-wxhaskell-part-3/
You can use wxHaskell variables, as ja suggested, for the same purpose, although I prefer the more explicit style I used in the blog.