caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Recursion on React.events.
@ 2009-12-09  2:40 Guillaume Yziquel
  2009-12-09  3:22 ` Guillaume Yziquel
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Guillaume Yziquel @ 2009-12-09  2:40 UTC (permalink / raw)
  To: OCaml List, Daniel Bünzli

Hello.

I've been dabbling with recursive definition of React events.

Suppose I have a function called schedule of type

	val schedule : Calendar.t -> unit React.event

which throws out an event at the specified time or date.

I've been trying to create a regular_schedule function that throws 
events at a regular pace. Daniel Bünzli's module is great, but sometimes 
a bit rough to get by, specifically on examples such as this one.

So I came up with a recursive definition of such a React.event:

> let rec regular_schedule start_time period =
>   React.E.switch React.E.never begin React.E.map
>     begin fun () -> regular_schedule (Calendar.add (Calendar.now ()) period) period end
>     begin schedule start_time end
>   end

First question:

It almost works, in the sense that if you insert a print_endline after 
the fun (), well, it indeeds prints stuff on stdin at the specified 
pace. However, somehow, the event as a whole behaves as React.E.never. 
So it doesn't work. I guess it has to do with the way React.switch works 
synchronously, but I really do not get it.

Second question:

Is there somehow a notion of 'tail recursion' for such constructs?

All the best,

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/


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

end of thread, other threads:[~2009-12-11 12:16 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-09  2:40 Recursion on React.events Guillaume Yziquel
2009-12-09  3:22 ` Guillaume Yziquel
2009-12-09  4:25 ` Daniel Bünzli
2009-12-09 18:47   ` Guillaume Yziquel
2009-12-10  8:39     ` Daniel Bünzli
2009-12-09  7:53 ` Daniel Bünzli
2009-12-09 11:23   ` [Caml-list] " Richard Jones
2009-12-09 18:01     ` Guillaume Yziquel
2009-12-10  3:38       ` Daniel Bünzli
2009-12-10 22:24         ` Guillaume Yziquel
2009-12-11 12:16           ` Jérémie Dimino
2009-12-09 18:24   ` Guillaume Yziquel
2009-12-10  8:24     ` Daniel Bünzli
2009-12-10 21:41       ` Guillaume Yziquel
2009-12-11  1:22         ` Daniel Bünzli

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