[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell
Subject:    Re: advice wanted on GUI design patterns
From:       Antony Courtney <antony () apocalypse ! org>
Date:       1999-09-27 20:04:56
Message-ID: 37EFCB95.1EB5B278 () apocalypse ! org
[Download RAW message or body]

Hi Havoc,

Havoc Pennington wrote:
> 
> [...]
> The question is: how do you structure a GUI program? The traditional OO
> program structure is the model-view architecture;
> [...]
> Clearly this will not fly in Haskell. So my previous experience does not
> map to writing a Haskell app.
>

There are a couple of answers to your question:

First, it is possible to write applications in Haskell using event loops
and mutable state.  Most of the simple toolkit bindings (such as
TclHaskell, which is really a binding to Tk) do this.

However, as you rightly observe, the event-dispatch model (or MVC model)
is critically dependent on mutable state, so isn't a particularly nice
match for functional programming languages.

There have been numerous attempts to develop more purely functional
models for interactive user interfaces.  The most recent (and, IMHO,
interesting / promising) work on this has been Functional Reactive
Programming (FRP).  The most mature application of FRP is Fran, a system
for Functional Reactive Animation.

The papers on FRP (refs. below) give much more detail, but essentially
the FRP programming model is concerned with expressing relationships
between discrete and continuous functions of an abstract model time. 
So, for example, the "inputs" to a graphical program are things like
mouse position (a continuous function of time), keyboard and mouse
button presses (events which occur at discrete points in time), and the
"outputs" can be modelled as either a screen image (a continuous
function of time) or as a sequence of drawing events (a discrete
function of time).  Programs are constructed by specifying a set of
equations which relate the output function of time in terms of the
inputs (which are also functions of time).  The resulting program is
thus purely declarative, and designing such a program has a striking
similarity to designing a digital circuit.  The implementations of
various FRP libraries take care of "animating" or "simulating" the
input-output relationship expressed by the program.
 
> As a concrete example, imagine you have a Boolean Editor. 
> [...]
> How do you write this program?

Sounds like an excellent excercise for getting started with FranTK.  :-)

For background information on FRP and its embodiment in Fran, check out:

	http://www.research.microsoft.com/users/conal/fran/

You might be particularly interested in "Declarative Event Oriented
Programming":

	http://research.microsoft.com/scripts/pubDB/pubsasp.asp?RecordID=188

which describes an interactive spline editor written in Fran.

There is also an FRP-style toolkit for Tk recently announced on this
list by Meurig Sage.  Check out:

	http://www.haskell.org/FranTk/

I've done a little work on diagrammatic / visual represetations of FRP
style programs; no refs. available yet, contact me if you're interested.

Hope that helps,

	-antony

-- 
Antony Courtney
antony@apocalypse.org
http://www.apocalypse.org/pub/u/antony



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic