Unfortunately, there doesn't seem to be a huge amount of work in
integrating Haskell with GUIs, relatively speaking. Perhaps one of the
most recent work in this arena is Haggis.
(http://www.dcs.gla.ac.uk/fp/software/haggis/) If I remember my Haggis
correctly, what you would probably do in this instance is setup a
"stream" for the checkbox and then have several different functions
running concurrently, one for each view. Each function would be a loop,
where at the top of the loop there is a blocking call: read
checkboxStream. When the `read' function returns, the loop continues on
to update the view appropriately.
Unlike in imperative languages, concurrency isn't much of a headache in
Haskell. There aren't any global or shared variables to worry about. If
you _want_ to share a variable across threads, you use an MVar, which is
very easy to use.
Hope this is kinda' what you were looking for,
- Michael Hobbs
Havoc Pennington wrote:
>
> 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