From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 3F8C27F30A for ; Fri, 8 Mar 2013 10:43:59 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.veber@gmail.com) identity=pra; client-ip=74.125.82.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of philippe.veber@gmail.com designates 74.125.82.173 as permitted sender) identity=mailfrom; client-ip=74.125.82.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-we0-f173.google.com) identity=helo; client-ip=74.125.82.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="postmaster@mail-we0-f173.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYBAKixOVFKfVKtgmdsb2JhbABDxh0IFg4BAQsJFBIGJIJZGQEbHgMSCQEGXQERAQUBIhuHeAEDD5oUgnKMMoJ7hGYKGScNWYhPAQUMkkcDkweDRI8PFimELQ X-IPAS-Result: AuYBAKixOVFKfVKtgmdsb2JhbABDxh0IFg4BAQsJFBIGJIJZGQEbHgMSCQEGXQERAQUBIhuHeAEDD5oUgnKMMoJ7hGYKGScNWYhPAQUMkkcDkweDRI8PFimELQ X-IronPort-AV: E=Sophos;i="4.84,806,1355094000"; d="scan'208";a="6072893" Received: from mail-we0-f173.google.com ([74.125.82.173]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 08 Mar 2013 10:43:58 +0100 Received: by mail-we0-f173.google.com with SMTP id x51so740068wey.18 for ; Fri, 08 Mar 2013 01:43:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=wYSK2WZIt8wXnCmzZdqd0sCkVPQXNH3uiXBTdNFk31A=; b=UlPc6bpb1CmwX57t83HNFJLjYIQpMgo8YYwdo/+pt6SPrVoOWewv5vRgB846WBjN/C mqDCT11InubLpji6r13dj8Q0B/zNlPhL7/djRJ1YDBF9c3O5W1rIjS3wTYWLVoTyCRl2 xFNA5qN+LiVjWx1OYjcIZYctGPEgzc//MlvA5FwNdGatLyTydD+IdDCOqQn4KZCJfVJQ h+4ztVmQvD7d53LJIAsy4E41KaA23OOvVNfrcN7cjAz94wdGXXaWWuW8yJEPUeYtmP5q dQ69pZjPO5gvkdWp60GRc8IFLwzrejO/R2Ll7NuploYDYsUuJplYmgGx6OsrkCmUz44K tx8w== X-Received: by 10.194.237.40 with SMTP id uz8mr2277428wjc.49.1362735838748; Fri, 08 Mar 2013 01:43:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.87.230 with HTTP; Fri, 8 Mar 2013 01:43:38 -0800 (PST) From: Philippe Veber Date: Fri, 8 Mar 2013 10:43:38 +0100 Message-ID: To: caml users Content-Type: multipart/alternative; boundary=089e0149372097664004d766a93f X-Validation-by: philippe.veber@gmail.com Subject: [Caml-list] Signals of signals in react --089e0149372097664004d766a93f Content-Type: text/plain; charset=ISO-8859-1 Dear functional-reactive camlers, In order to change the dependencies between signals dynamically, one can use the switch function whose type is: utop $ React.S.switch;; - : ?eq:('a -> 'a -> bool) -> 'a React.signal -> 'a React.signal React.event -> 'a React.signal = However I often find myself wanting to write signals of signals, and I wrote the following definition to cope with them: val bind_s : 'a React.signal -> ('a -> 'b React.signal) -> 'b React.signal let bind_s s f = let s' = S.map ~eq:( == ) f s in let init = S.value s' and changes = S.changes s' in S.switch init changes So far it worked as I thought it would, but still I'm not really confident this is a safe use of signals. Does anyone see a potential pitfall here? Cheers, Philippe. PS at least, there should be an eq optional attribute to [bind_s], and the last line should be [S.switch ~eq init changes] --089e0149372097664004d766a93f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Dear functional-reactive camlers,

In order to change the dependencie= s between signals dynamically, one can use the switch function whose type i= s:

utop $ React.S.switch;;
- : ?eq:('a -> 'a -> boo= l) -> 'a React.signal -> 'a React.signal React.event -> &#= 39;a React.signal =3D <fun>

However I often find myself wanting to write signals of signals, and I = wrote the following definition to cope with them:

val bind_s : 'a React.signal -> (= 9;a -> 'b React.signal) -> 'b React.signal
let bind_s s f =3D
=A0 let s' =3D S.map ~eq:( =3D=3D ) f s in
= =A0 let init =3D S.value s'
=A0 and changes =3D S.changes s' in<= br>=A0 S.switch init changes

So far it worked as I thought it= would, but still I'm not really confident this is a safe use of signal= s. Does anyone see a potential pitfall here?

Cheers,
=A0 Philippe.

PS at least, there should be an eq opti= onal attribute to [bind_s], and the last line should be [S.switch ~eq init changes]

--089e0149372097664004d766a93f--