Hi,
I'm trying to learn Haskell, and I'm wondering what experiences people
have with designing programs with graphical user interfaces. Assume for
the moment that a GUI implies an object-oriented existing library such as
GTK+ or Tk or whatever Windows uses, since this is probably the only
realistic option in the immediate future. So GUI access involves IO and
the GUI has state and can be mutated, etc.
The question is: how do you structure a GUI program? The traditional OO
program structure is the model-view architecture; you have a data
structure ("model"), and one or more graphical representations ("views");
via signals/slots or "listeners" the views update automatically when the
model changes, keeping GUI state in sync with the data.
The other traditional aspect of GUI program structure is the event loop;
so I get an event, change the model accordingly, the change ripples
through all the views keeping their state in sync; the model's state is
updated and can be re-accessed when I get the next event.
Clearly this will not fly in Haskell. So my previous experience does not
map to writing a Haskell app.
As a concrete example, imagine you have a Boolean Editor. This is a
program which loads documents; each document contains a single boolean
value. The editor is just a window with a check button, so you can toggle
the boolean value. You can have any number of windows for a single
document; you can have any number of documents open, and you should be
able to load and save them. If you toggle the same document in one of its
windows, the other windows should update.
Imagine you have functions to create a check button window, query its
state (True or False), and set its state.
How do you write this program?
I'm interested in sample real-world source code if people have written GUI
apps in Haskell, as well.
If the question isn't clear please say so. :-)
Thanks for any insights,
Havoc