caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Functional Reactive GUI for O'Caml
@ 2006-12-20 15:38 Chris King
  2006-12-20 16:20 ` [Caml-list] " Virgile Prevosto
  2006-12-20 17:00 ` Gabriel Kerneis
  0 siblings, 2 replies; 7+ messages in thread
From: Chris King @ 2006-12-20 15:38 UTC (permalink / raw)
  To: caml-list

(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/


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Functional Reactive GUI for O'Caml
  2006-12-20 15:38 Functional Reactive GUI for O'Caml Chris King
@ 2006-12-20 16:20 ` Virgile Prevosto
  2006-12-20 22:34   ` Jonathan Roewen
  2006-12-20 17:00 ` Gabriel Kerneis
  1 sibling, 1 reply; 7+ messages in thread
From: Virgile Prevosto @ 2006-12-20 16:20 UTC (permalink / raw)
  To: caml-list

Hello,
Le mer 20 déc 2006 10:38:22 CET,
"Chris King" <colanderman@gmail.com> a écrit :


> 
>     * 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.

You might be interested by Reactive ML: http://rml.inria.fr
This is a whole language (based on Ocaml), not a library, though.

-- 
E tutto per oggi, a la prossima volta.
Virgile


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Functional Reactive GUI for O'Caml
  2006-12-20 15:38 Functional Reactive GUI for O'Caml Chris King
  2006-12-20 16:20 ` [Caml-list] " Virgile Prevosto
@ 2006-12-20 17:00 ` Gabriel Kerneis
  2006-12-21  3:36   ` Chris King
  1 sibling, 1 reply; 7+ messages in thread
From: Gabriel Kerneis @ 2006-12-20 17:00 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 724 bytes --]

Le Wed, 20 Dec 2006 10:38:22 -0500, "Chris King"
<colanderman@gmail.com> a écrit :
>     * Is the API clear and understandable? e.g. does the above example
> make sense, even to those not familiar with functional reactive
> programming?

Not at all. I must say this is the very first time I've met reactive
programming. But although the underlying concept seems clear to me, I
can't figure out how your example is working.

It might have been clearer if I had read a quick tutorial or how-to
before. But your question targeted newbies, so let me give you a
total newbie's answer : I just can't get it ;-)

It seems interesting though, I think I'll have a look at it in a near
future.
-- 
Gabriel Kerneis


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Functional Reactive GUI for O'Caml
  2006-12-20 16:20 ` [Caml-list] " Virgile Prevosto
@ 2006-12-20 22:34   ` Jonathan Roewen
  2006-12-21 10:04     ` Virgile Prevosto
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Roewen @ 2006-12-20 22:34 UTC (permalink / raw)
  To: Virgile Prevosto; +Cc: caml-list

On 12/21/06, Virgile Prevosto <virgile.prevosto@m4x.org> wrote:
> Hello,
> Le mer 20 déc 2006 10:38:22 CET,
> "Chris King" <colanderman@gmail.com> a écrit :
>
>
> >
> >     * 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.
>
> You might be interested by Reactive ML: http://rml.inria.fr
> This is a whole language (based on Ocaml), not a library, though.

I can't get rmlc to work :-( Being in a cygwin environment possibly
doesn't help much, but it can't find rml_pervasives.rzi. There doesn't
seem to be a src package available either...

Jonathan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Functional Reactive GUI for O'Caml
  2006-12-20 17:00 ` Gabriel Kerneis
@ 2006-12-21  3:36   ` Chris King
  0 siblings, 0 replies; 7+ messages in thread
From: Chris King @ 2006-12-21  3:36 UTC (permalink / raw)
  To: Gabriel Kerneis; +Cc: caml-list

On 12/20/06, Gabriel Kerneis <gabriel.kerneis@enst.fr> wrote:
> It might have been clearer if I had read a quick tutorial or how-to
> before. But your question targeted newbies, so let me give you a
> total newbie's answer : I just can't get it ;-)

You have a very good point :) nothing's intuitive unless it's
familiar, which I admit the syntax (especially lift) is not.  I intend
to post some examples as well as a tutorial in the next few weeks, but
for the time being here is a quick breakdown of the above example
(with a few math fixes :P):

> open Fr
> open FrGui
Fr is the library containing funcitons to create functional reactive
expressions; FrGui contains definitions of all the GUI widgets.

> let float_view f = text_view (lift (string_of_float @f))
This one-liner defines the float_view widget in terms of the text_view
widget.  Ignoring the definition (which should make more sense later),
it's simply a function which creates a widget which displays the
time-varying floating-point value f.

> let _ =
>   let temp_box, temp = spin_box 20. in
spin_box is a function which creates a widget (temp_box) which allows
the user to input a floating-point value (in this case, the
temperature we want to convert).  Here 20 is given as its initial
value.  The current value of temp_box is stored in temp.  This value
can change with time and is called a "behavior" (and has the type
float behavior).

>    let fahrenheit = lift (@temp *. 1.8 +. 32.)
Because temp is not a float but a float behavior, we must use a
special construct to access it.  lift (expr) allows us to access
values contained in behaviors and to create new ones.  Inside of expr
(which is otherwise a normal O'Caml expression), we can use the form
@expr to reference a behavior (think of this like dereferencing a
pointer in C). Here, fahrenheit is a behavior which is always equal to
the value of (temp *. 1.8 +. 32.).  Whenever temp changes, so does
fahrenheit.

>    and celsuis = lift ((@temp -. 32.) /. 1.8) in
Here, we similarly define celsius as a float behavior which is
dependent on the current value of temp.

>    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
Here we define the main window.  hbox, vbox, and label are all
functions which create widgets.  hbox and vbox pack lists of widgets
horizontally and vertically, and label creates a text label.  temp_box
is the widget instance we defined above, which allows the user to
enter the value of temp.  We also create two instances of the
float_view widget, to display the values of fahrenheit and celsius.

>    run_dialog (main_window, main_window#close)
This incantation displays main_window and enters the GUI's main loop
until the window's close button is clicked.

The end result is a window with a spin box into which the user can
input a temperature.  That temperature is instantly converted into
both Fahrenheit and Celsius and displayed in two other text boxes (the
float_views) in the window.

Hopefully this description helped more than it confused... if it did
more of the latter then I'll try to post a proper tutorial on the
O'Caml RT website as soon as possible, since one is in order anyway.
Thanks for you input :)

- Chris


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Functional Reactive GUI for O'Caml
  2006-12-20 22:34   ` Jonathan Roewen
@ 2006-12-21 10:04     ` Virgile Prevosto
  0 siblings, 0 replies; 7+ messages in thread
From: Virgile Prevosto @ 2006-12-21 10:04 UTC (permalink / raw)
  To: caml-list

Le jeu 21 déc 2006 11:34:23 CET,
"Jonathan Roewen" <jonathan.roewen@gmail.com> a écrit :

> > You might be interested by Reactive ML: http://rml.inria.fr
> > This is a whole language (based on Ocaml), not a library, though.
> 
> I can't get rmlc to work :-( Being in a cygwin environment possibly
> doesn't help much, but it can't find rml_pervasives.rzi. There doesn't
> seem to be a src package available either...

Well, my experience with Reactive ML consists mainly in having seen the
demos during Louis Mandel's defence... And that's still better than my
experience on cygwin+ocaml.

Thus, I'm afraid that I can't do much, except forwarding your mail to
the authors and suggesting that you get in touch with them directly.

-- 
E tutto per oggi, a la prossima volta.
Virgile


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Functional Reactive GUI for O'Caml
@ 2006-12-21  8:31 Louis Mandel
  0 siblings, 0 replies; 7+ messages in thread
From: Louis Mandel @ 2006-12-21  8:31 UTC (permalink / raw)
  To: caml-list

A source distribution of ReactiveML will be available soon.

You may also have a look to Lucid Synchrone which is closer
to the functional reactive programming model.

http://www.lri.fr/~pouzet/lucid-synchrone

--
Louis Mandel

Jonathan Roewen wrote:
 > On 12/21/06, Virgile Prevosto <virgile.prevosto@m4x.org> wrote:
 > > Hello,
 > > Le mer 20 déc 2006 10:38:22 CET,
 > > "Chris King" <colanderman@gmail.com> a écrit :
 > >
 > >
 > > >
 > > >     * 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.
 > >
 > > You might be interested by Reactive ML: http://rml.inria.fr
 > > This is a whole language (based on Ocaml), not a library, though.
 >
 > I can't get rmlc to work :-( Being in a cygwin environment possibly
 > doesn't help much, but it can't find rml_pervasives.rzi. There doesn't
 > seem to be a src package available either...
 >
 > Jonathan


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-12-21 10:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-20 15:38 Functional Reactive GUI for O'Caml Chris King
2006-12-20 16:20 ` [Caml-list] " Virgile Prevosto
2006-12-20 22:34   ` Jonathan Roewen
2006-12-21 10:04     ` Virgile Prevosto
2006-12-20 17:00 ` Gabriel Kerneis
2006-12-21  3:36   ` Chris King
2006-12-21  8:31 Louis Mandel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).