Browse thread
Recursion on React.events.
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Guillaume Yziquel <guillaume.yziquel@c...> |
| Subject: | Recursion on React.events. |
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/