Version franaise
Home About Download Resources Contact us

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Recursion on
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-12-09 (07:53)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: Re: Recursion on
> Daniel Bünzli's module is great, but sometimes a bit rough
> to get by, specifically on examples such as this one.

I would just like to point out that this has nothing to do with the
module per se but understanding frp in general and this is the reason
why I went to great length to document the semantics for each of the
combinators I provide --- something most frp libraries won't bother to
do, leaving you with testing or looking into the implementation for
understanding things when tricky simulateneity issues arise.

Thus to understand why your event didn't work you could have done the
following. Provided you understand the notations given here :

1) Define a semantics for your primitive events and functions.

 [Calendar.schedule st]_t = Some () iff t = st
 [ ()]_t = t

2) Reason on your expression, by applying the semantics of the
combinators and your primitives.

Let's try to look what happens at st for (regular_schedule st p)
assuming p > 0.

 [regular_schedule st p]_st =
 [E.switch E.never ee]_st
 with ee = (fun () -> regular_schedule ...) (schedule st)

Since we have [schedule st]_st = Some (), by the semantics of we
have [ee]_st = Some ev. Thus we are in the second case of the semantics
of E.switch (see doc) and the semantics of the switch reduces to the
semantics of ev, i.e.

 [E.switch E.never ee]_st =
 [regular_schedule (Calendar.add ( ()) p) p]_st =
 [E.switch E.never ee']_st
 with ee' = (fun () -> regular_schedule ..) (schedule (st + p))

Now by the semantics of schedule and you know nothing will
happen on ee' before st + p ans since p > 0 we are in the first case
of the semantics of E.switch and the last switch reduces to the
semantics of E.never. To sum up :

 [regular_schedule st p]_st = [E.never]_st = None

So at st, nothing happens, as you witnessed. Applying the same
technique you could generalize the result for any t.

Pure equational reasoning, it's not that hard, or is it ?



P.S. In my previous email

 let reschedule () = Calendar.add ( ()) period

should read

 let reschedule () = schedule (Calendar.add ( ()) period)

I misunderstood the type of Calendar.add.