From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 52591BC37 for ; Wed, 9 Dec 2009 08:53:37 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgkBAO/lHkvRVdvdkGdsb2JhbACEJpZ9PwEBAQEJCQwHEwOqXoFZhXKIaQECAwWBKoIqUwSCfIgp X-IronPort-AV: E=Sophos;i="4.47,367,1257116400"; d="scan'208";a="38267058" Received: from mail-ew0-f221.google.com ([209.85.219.221]) by mail2-smtp-roc.national.inria.fr with ESMTP; 09 Dec 2009 08:53:37 +0100 Received: by ewy21 with SMTP id 21so269742ewy.22 for ; Tue, 08 Dec 2009 23:53:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=eekTpL3elyz4JXONyfhiCBvHVZiJZecWey8GtOTy9MA=; b=SlP7vDXPosGZ8WqXSvWKf1/XypfEJKoe05gQwb6roloJ7vAAL+Q8XGqkVVSiEv3un7 oV5Qi9dF8aX2V6GVP5wrNJcIn7nzKqZBxyPv+V08dWfxVnoOnBTDr1mIR7Qi36k4bCPb Euhr60KS1lE8Obvw3igt63fo83/zRfPjygaLc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=Am/GWJAsaPN9yBWGaesSVonj0enuX9QUkZODsDvPItq7gtg+Xs9/DwWOxGPIjrBDwX gW9zNNa9U3zwJUgPjE61H7x0I0ow8RJ7GF6w/dQu2uWvjTQavC3n3yAOUubMgsoYRH4d vKfdCcfBEVQ+IyorVdOtUoCi51DBH/s2wQU5Y= MIME-Version: 1.0 Sender: daniel.c.buenzli@gmail.com Received: by 10.213.15.14 with SMTP id i14mr10219637eba.50.1260345216816; Tue, 08 Dec 2009 23:53:36 -0800 (PST) In-Reply-To: <4B1F0E3A.3040907@citycable.ch> References: <4B1F0E3A.3040907@citycable.ch> Date: Wed, 9 Dec 2009 15:53:36 +0800 X-Google-Sender-Auth: 5325efa54f0f2660 Message-ID: <91a3da520912082353m5c75f307j6f9542877d84841f@mail.gmail.com> Subject: Re: Recursion on React.events. From: =?UTF-8?Q?Daniel_B=C3=BCnzli?= To: guillaume.yziquel@citycable.ch Cc: OCaml List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; recursion:01 buenzli:01 semantics:01 combinators:01 notations:01 semantics:01 combinators:01 reschedule:98 reschedule:98 functions:01 primitives:01 define:02 expression:02 primitive:02 module:03 > Daniel B=C3=BCnzli'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 =3D Some () iff t =3D st [Calendar.now ()]_t =3D 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 =3D [E.switch E.never ee]_st with ee =3D E.map (fun () -> regular_schedule ...) (schedule st) Since we have [schedule st]_st =3D Some (), by the semantics of E.map we have [ee]_st =3D 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 =3D [regular_schedule (Calendar.add (Calendar.now ()) p) p]_st =3D [E.switch E.never ee']_st with ee' =3D 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 =3D [E.never]_st =3D 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 () =3D Calendar.add (Calendar.now ()) period should read let reschedule () =3D schedule (Calendar.add (Calendar.now ()) period) I misunderstood the type of Calendar.add.