开发者

StateT and WX gui coexistance

开发者 https://www.devze.com 2022-12-22 09:54 出处:网络
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.

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 be开发者_如何学Ccomes 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消