Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top