Version française
Home     About     Download     Resources     Contact us    
Browse thread
Functional Reactive GUI for O'Caml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chris King <colanderman@g...>
Subject: Functional Reactive GUI for O'Caml
(Cross-posted from Lambda the Ultimate at the advice of Yaron Minsky...)

Hi all,

I've been working for the past few months on a functional reactive GUI
system for O'Caml called "O'Caml Reactive Toolkit", "functional
reactive" meaning that functional expressions can be built whose
values change over time in response to user input without relying on
imperative constructs (much like dataflow or visual programming
languages).  For those familiar with extant FR systems, the core FR
logic is based heavily on Haskell's Yampa, while the FR API is modeled
after PLT Scheme's FrTime, so there is not much new there. The novelty
is in the GUI API, which, although layered on lablgtk2, constructs a
GUI via functions rather than objects and exposes no mutable state:
response to user input is modeled using functional reactive
constructs.  As an example, here is a toy temperature conversion
program:

open Fr
open FrGui

let float_view f = text_view (lift (string_of_float @f))

let _ =
    let temp_box, temp = spin_box 20. in
    let fahrenheit = lift ((@temp -. 32.) *. 1.8)
    and celsuis = lift (@temp /. 1.8 +. 32.) in
    let main_window = window
        ~title: "Temperature converter"
        (hbox [
            hbox [label "Convert "; temp_box; label " to:"];
            vbox [
                hbox [label "degrees Fahrenheit: "; float_view fahrenheit];
                hbox [label "degrees Celsius: "; float_view celsius]]]) in
    run_dialog (main_window, main_window#close)

The temperature entered by the user is instantly converted to both
degrees Fahrenheit and degrees Celsius.  The "lift" construct is a
camlp4 syntax extension which provides a way to create functional
reactive expressions: inside it, "@val" refers to a value which
changes with time (a "behavior").

Though O'Caml RT is far from complete I made a prerelease because I
want to solicit feedback from others who are interested in functional
reactive programming and in creating a portable GUI API for O'Caml. I
made a web page[1] providing links to the source code, documentation
(on both functional reactive programming and FrGui), and (coming soon)
examples. It's known to compile both to bytecode and native code on
Mac OS X and Linux (feedback from Windows users would be greatly
appreciated!), and it should be possible already to write many simple
GUI applications using it.

My questions to you are:

    * Am I duplicating work? I know of functional reactive GUI systems
such as Fudgets, SuperGlue, and Flapjax for other languages but I know
of no such system for O'Caml.
    * What would you want to see in a functional-reactive GUI toolkit?
i.e. what things which are often awkward to express in procedural
langauges do you think should be made easy in O'Caml RT?
    * What are some examples of things which are easy in procedural
languages but you think would be awkward in a functional-reactive
setting?
    * Is the API clear and understandable? e.g. does the above example
make sense, even to those not familiar with functional reactive
programming?

Thanks in advance for your feedback!

[1] http://users.wpi.edu/~squirrel/ocamlrt/