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 8403BBC37 for ; Wed, 9 Dec 2009 03:40:40 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnkEAEedHktV2gB4h2dsb2JhbACEJZRfgl0BAQEKCwgcqyeQOoEvgixXBIkb X-IronPort-AV: E=Sophos;i="4.47,365,1257116400"; d="scan'208";a="38257593" Received: from emailfrontal1.citycable.ch ([85.218.0.120]) by mail2-smtp-roc.national.inria.fr with SMTP; 09 Dec 2009 03:40:40 +0100 Received: from [192.168.0.12] (unknown [85.218.92.99]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal1.citycable.ch (Postfix) with ESMTPA id C64F712C1DB; Wed, 9 Dec 2009 03:40:38 +0100 (CET) Message-ID: <4B1F0E3A.3040907@citycable.ch> Date: Wed, 09 Dec 2009 03:40:58 +0100 From: Guillaume Yziquel Reply-To: guillaume.yziquel@citycable.ch User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: OCaml List , =?UTF-8?B?RGFuaWVsIELDvG56bGk=?= Subject: Recursion on React.events. Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; guillaume:01 guillaume:01 recursion:01 recursive:01 val:01 recursive:01 endline:01 stdin:01 rec:01 behaves:02 constructs:02 module:03 unit:03 let:03 notion:04 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=20 events at a regular pace. Daniel B=C3=BCnzli's module is great, but somet= imes=20 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 =3D > React.E.switch React.E.never begin React.E.map > begin fun () -> regular_schedule (Calendar.add (Calendar.now ()) pe= riod) period end > begin schedule start_time end > end First question: It almost works, in the sense that if you insert a print_endline after=20 the fun (), well, it indeeds prints stuff on stdin at the specified=20 pace. However, somehow, the event as a whole behaves as React.E.never.=20 So it doesn't work. I guess it has to do with the way React.switch works=20 synchronously, but I really do not get it. Second question: Is there somehow a notion of 'tail recursion' for such constructs? All the best, --=20 Guillaume Yziquel http://yziquel.homelinux.org/