caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Functional Reactive Programming in OCaml?
@ 2004-11-29  0:44 Benjamin Pierce
  2004-11-29 18:02 ` [Caml-list] " james woodyatt
  2004-11-30  3:02 ` Benjamin Pierce
  0 siblings, 2 replies; 8+ messages in thread
From: Benjamin Pierce @ 2004-11-29  0:44 UTC (permalink / raw)
  To: caml-list

I'm sure that, like me, many of you have experienced language-envy when you've seen the very cool libraries for Functional Reactive Programming (Fran, Frob, Yampa, etc.) that have been implemented in the Haskell world.

Has anybody tried to do something similar in OCaml?  At first sight, it does not seem trivial: the implementations of FRP that I've seen make good use of many of Haskell's special features -- laziness, type classes and qualified types, monads, etc...

Thanks for any pointers,

    - Benjamin

-----------------------------------------------------------------------------
BENJAMIN C. PIERCE, Professor                                               
Dept. of Computer & Information Science     
University of Pennsylvania                                    +1 215 898-2012
3330 Walnut St.                                          Fax: +1 215 898-0587
Philadelphia, PA 19104, USA                http://www.cis.upenn.edu/~bcpierce
-----------------------------------------------------------------------------


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

* Re: [Caml-list] Functional Reactive Programming in OCaml?
  2004-11-29  0:44 Functional Reactive Programming in OCaml? Benjamin Pierce
@ 2004-11-29 18:02 ` james woodyatt
  2004-11-30  3:02 ` Benjamin Pierce
  1 sibling, 0 replies; 8+ messages in thread
From: james woodyatt @ 2004-11-29 18:02 UTC (permalink / raw)
  To: bcpierce; +Cc: Caml List

On 28 Nov 2004, at 16:44, Benjamin Pierce wrote:
>
> I'm sure that, like me, many of you have experienced language-envy 
> when you've seen the very cool libraries for Functional Reactive 
> Programming (Fran, Frob, Yampa, etc.) that have been implemented in 
> the Haskell world.
>
> Has anybody tried to do something similar in OCaml?  At first sight, 
> it does not seem trivial: the implementations of FRP that I've seen 
> make good use of many of Haskell's special features -- laziness, type 
> classes and qualified types, monads, etc...
>
> Thanks for any pointers,

Hello, Dr. Pierce.  Yes, I've tried this.  Reactive programming is a 
hobby of mine.  I haven't tried building a functional GUI toolkit, 
since I'm mostly interested in network application services.  But you 
might try checking out the Iom module in my OCaml Network Application 
Environment project on SourceForge.

	<http://sf.net/projects/ocnae/>

Basically, I ported Chapter 30 of Magnus Carlsson's and Thomas 
Hallgren's joint Ph.D. thesis to OCaml, then generalized it and rewrote 
it to take advantage of OCaml's mutable data structures inside the 
scheduler.

	<http://www.cs.chalmers.se/~hallgren/Thesis>

Be advised: the most current release of Cf_gadget has a serious stack 
leak in the scheduler, causing some trivial reactors explode on the 
stack.  A fix-- involving yet another complete rewrite of the 
scheduler-- is already in CVS, and a new release will be coming soon.


-- 
j h woodyatt <jhw@wetware.com>
markets are only free to the people who own them.


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

* Re: Functional Reactive Programming in OCaml?
  2004-11-29  0:44 Functional Reactive Programming in OCaml? Benjamin Pierce
  2004-11-29 18:02 ` [Caml-list] " james woodyatt
@ 2004-11-30  3:02 ` Benjamin Pierce
  2004-11-30 17:33   ` [Caml-list] " Vincenzo Ciancia
  1 sibling, 1 reply; 8+ messages in thread
From: Benjamin Pierce @ 2004-11-30  3:02 UTC (permalink / raw)
  Cc: caml-list

Many thanks to all those who've replied so far to my query about Functional
Reactive Programming in OCaml.  I got some very interesting pointers, but
none closely related to what I was looking for.

I should have been more precise in what I asked -- "FRP" in the Haskell
community is a term with a much more specific technical meaning than just
"reactive programming in a functional style": I was thinking of the line of
work initiated by Conal Eliott and Paul Hudak in their Fran library and
continued in systems like Frob, Fruit, and recently Yampa.  

The common idea in these systems is to introduce an abstraction of "signals"
-- roughly, functions from time to "values", where the values can be
anything from real numbers (conventional signal-processing-type signals) to
two- or three-dimensional pictures, to booleans (representing events).
What's special is that time is represented as a continuous, real-number
quantity.  They do all kinds of work behind the scenes to actually compute
with behaviors, but what shows through in the API is a very simple, elegant,
and powerful set of primitives that can be combined in straightforward ways
to achieve very complex effects.  See http://www.haskell.org/frp/ for more
info. 

So... is anybody doing THAT in OCaml?

Thanks for any (more) pointers,

   Benjamin



> I'm sure that, like me, many of you have experienced language-envy when you've seen the very cool libraries for Functional Reactive Programming (Fran, Frob, Yampa, etc.) that have been implemented in the Haskell world.
> 
> Has anybody tried to do something similar in OCaml?  At first sight, it does not seem trivial: the implementations of FRP that I've seen make good use of many of Haskell's special features -- laziness, type classes and qualified types, monads, etc...
> 
> Thanks for any pointers,
> 
>     - Benjamin
> 
> -----------------------------------------------------------------------------
> BENJAMIN C. PIERCE, Professor                                               
> Dept. of Computer & Information Science     
> University of Pennsylvania                                    +1 215 898-2012
> 3330 Walnut St.                                          Fax: +1 215 898-0587
> Philadelphia, PA 19104, USA                http://www.cis.upenn.edu/~bcpierce
> -----------------------------------------------------------------------------


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

* Re: [Caml-list] Re: Functional Reactive Programming in OCaml?
  2004-11-30  3:02 ` Benjamin Pierce
@ 2004-11-30 17:33   ` Vincenzo Ciancia
  2004-12-01 17:14     ` Florian Hars
  0 siblings, 1 reply; 8+ messages in thread
From: Vincenzo Ciancia @ 2004-11-30 17:33 UTC (permalink / raw)
  To: caml-list; +Cc: bcpierce

On Tuesday 30 November 2004 04:02, Benjamin Pierce wrote:
> The common idea in these systems is to introduce an abstraction of
> "signals" -- roughly, functions from time to "values", where the
> values can be anything from real numbers (conventional
> signal-processing-type signals) to two- or three-dimensional
> pictures, to booleans (representing events). What's special is that
> time is represented as a continuous, real-number quantity.  They do
> all kinds of work behind the scenes to actually compute with
> behaviors, but what shows through in the API is a very simple,
> elegant, and powerful set of primitives that can be combined in
> straightforward ways to achieve very complex effects.

I am surely not an expert on the subject, but I tried this at home in a 
student project at university. I wrote a library for composition of 
monomorphic signal functions. It was just a simple attempt but I found 
two things:

1. arrow composition in haskell can be very efficient - you usually 
implement your actions in terms of IO actions, and IO actions 
composition is _I suppose_ optimized somewhat by the compiler, e.g. 
inlining functions as needed to form a bigger code block. However you 
can compose as many arrows as you want without degrading performance.

Parallel or sequential arrow composition in ocaml will certainly involve 
- as in the haskell implementation - something "like" function 
composition, and this will result in efficiency proportional to the 
number of functions involved, which is unwanted. The performance gap 
between an event-based loop and "fran-like" code is discouraging for 
this reason. But you could generate bytecode at runtime and avoid this 
problem (and even beat haskell to please your language envy :)). I 
would seriously consider the second alternative if I had the time to 
work on it.

2. you are sometimes constrained to reveal implementation of your arrows 
when implementing composition, due to the value restriction - you 
certainly know this better than me, and I couldn't explain this 
anymore, the search function on the mailing list archives is not 
working or else I'd find an example I posted years ago and forgot 
about :) If you are interest I'll download the raw archives and find 
it.

Hope this helps - I would be interested in an implementation of FRAN for 
ocaml even if I am not so sure that I might be of any help.

Vincenzo


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

* Re: [Caml-list] Re: Functional Reactive Programming in OCaml?
  2004-11-30 17:33   ` [Caml-list] " Vincenzo Ciancia
@ 2004-12-01 17:14     ` Florian Hars
  2004-12-02  8:04       ` Vincenzo Ciancia
  0 siblings, 1 reply; 8+ messages in thread
From: Florian Hars @ 2004-12-01 17:14 UTC (permalink / raw)
  To: Vincenzo Ciancia; +Cc: caml-list, bcpierce

Vincenzo Ciancia wrote:
> the search function on the mailing list archives is not 
> working or else I'd find an example I posted years ago and forgot 
> about :)

http://groups.google.com/groups?q=vincenzo%20caml-list%20arrow
works for me, at least if October 2003 qualifies as "years ago".

Yours, Florian.


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

* Re: [Caml-list] Re: Functional Reactive Programming in OCaml?
  2004-12-01 17:14     ` Florian Hars
@ 2004-12-02  8:04       ` Vincenzo Ciancia
  0 siblings, 0 replies; 8+ messages in thread
From: Vincenzo Ciancia @ 2004-12-02  8:04 UTC (permalink / raw)
  To: caml-list

On Wednesday 01 December 2004 18:14, Florian Hars wrote:
> http://groups.google.com/groups?q=vincenzo%20caml-list%20arrow
> works for me, at least if October 2003 qualifies as "years ago".

Yes it's the message I was referring to, I tried with different queries 
and couldn't find it on google, thanks. It's ages ago for my mind, 
because I was still undergraduate then, and my life completely changed 
in the meantime :)

V.


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

* Re: [Caml-list] Functional Reactive Programming in OCaml?
  2004-11-30  6:36 [Caml-list] " Gregoire Hamon
@ 2004-11-30 14:14 ` Benjamin Pierce
  0 siblings, 0 replies; 8+ messages in thread
From: Benjamin Pierce @ 2004-11-30 14:14 UTC (permalink / raw)
  To: Gregoire Hamon; +Cc: caml-list

> you can look at Lucid Synchrone (http://www-spi.lip6.fr/lucid-synchrone/),
> a functional language dedicated to reactive programming. The syntax is
> OCaml's and the compiler produces OCaml code (combining both languages is
> easy).
> ...
> You can write Fran-like code quite easily (I had some examples which I
> can try to find if you're interested).

Yes, I would be interested if you can dig them up.  I'm surprised, though --
I had the impression from the homepage that Lucid-Synchrone was a clocked
language and could not deal with continuous time.

    - Benjamin

-----------------------------------------------------------------------------
BENJAMIN C. PIERCE, Professor                                               
Dept. of Computer & Information Science     
University of Pennsylvania                                    +1 215 898-2012
3330 Walnut St.                                          Fax: +1 215 898-0587
Philadelphia, PA 19104, USA                http://www.cis.upenn.edu/~bcpierce
-----------------------------------------------------------------------------


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

* Re: [Caml-list] Functional Reactive Programming in OCaml?
@ 2004-11-30  6:36 Gregoire Hamon
  2004-11-30 14:14 ` Benjamin Pierce
  0 siblings, 1 reply; 8+ messages in thread
From: Gregoire Hamon @ 2004-11-30  6:36 UTC (permalink / raw)
  To: caml-list

> I'm sure that, like me, many of you have experienced language-envy
> when you've seen the very cool libraries for Functional Reactive
> Programming (Fran, Frob, Yampa, etc.) that have been implemented in
> the Haskell world.
>
> Has anybody tried to do something similar in OCaml?  At first sight,
> it does not seem trivial: the implementations of FRP that I've seen
> make good use of many of Haskell's special features -- laziness, type
> classes and qualified types, monads, etc...
>
> Thanks for any pointers,

you can look at Lucid Synchrone (http://www-spi.lip6.fr/lucid-synchrone/),
a functional language dedicated to reactive programming. The syntax is
OCaml's and the compiler produces OCaml code (combining both languages is
easy).

While being stream based, reactivity, which is ensured statically, allows
the compiler to produce purely sequential (strict) code.

You can write Fran-like code quite easily (I had some examples which I
can try to find if you're interested).

Gregoire.





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

end of thread, other threads:[~2004-12-02  8:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-29  0:44 Functional Reactive Programming in OCaml? Benjamin Pierce
2004-11-29 18:02 ` [Caml-list] " james woodyatt
2004-11-30  3:02 ` Benjamin Pierce
2004-11-30 17:33   ` [Caml-list] " Vincenzo Ciancia
2004-12-01 17:14     ` Florian Hars
2004-12-02  8:04       ` Vincenzo Ciancia
2004-11-30  6:36 [Caml-list] " Gregoire Hamon
2004-11-30 14:14 ` Benjamin Pierce

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