caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
To: guillaume.yziquel@citycable.ch
Cc: OCaml List <caml-list@inria.fr>
Subject: Re: Recursion on React.events.
Date: Wed, 9 Dec 2009 15:53:36 +0800	[thread overview]
Message-ID: <91a3da520912082353m5c75f307j6f9542877d84841f@mail.gmail.com> (raw)
In-Reply-To: <4B1F0E3A.3040907@citycable.ch>

> 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 :

http://erratique.ch/software/react/doc/React#sem


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

 [Calendar.schedule st]_t = Some () iff t = st
 [Calendar.now ()]_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 = E.map (fun () -> regular_schedule ...) (schedule st)

Since we have [schedule st]_st = Some (), by the semantics of E.map 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 (Calendar.now ()) p) p]_st =
 [E.switch E.never ee']_st
 with ee' = E.map (fun () -> regular_schedule ..) (schedule (st + p))

Now by the semantics of schedule and E.map 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 ?

Best,

Daniel

P.S. In my previous email

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

should read

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

I misunderstood the type of Calendar.add.


  parent reply	other threads:[~2009-12-09  7:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-09  2:40 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=91a3da520912082353m5c75f307j6f9542877d84841f@mail.gmail.com \
    --to=daniel.buenzli@erratique.ch \
    --cc=caml-list@inria.fr \
    --cc=guillaume.yziquel@citycable.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).