[Haskell-cafe] adding state in GUIs (qtHaskell)

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Thu Sep 10 16:43:54 EDT 2009

On Wed, 2009-09-09 at 18:29 -0700, Michael P Mossey wrote:
> I'm trying to learn qtHaskell. I realize few people on this list know anything 
> about qtHaskell, but I have a question that probably relates to all GUIs as 
> implemented in Haskell. I just need a hint that could help me figure out the 
> next step, which I might be able to infer from the qtHaskell API.

Ultimately it's done by some kind of mutable state, either an IORef,
MVar or a thread.

On top of these you can layer nicer stuff like a state monad (with a
'runState' function that saves and restores from an IORef).

A personal favourite of mine is having the GUI event handler post data
over a channel to a thread. That thread reads from the channel and deals
with the events. The state of the GUI app is then held as local
parameters in that thread.

Doing this of course requires that the GUI lib you're using can cope
with normal Haskell (forkIO) threads. This is possible with gtk2hs, I
don't know about the others.


More information about the Haskell-Cafe mailing list