From: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
To: Philippe Veber <philippe.veber@gmail.com>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Signals of signals in react
Date: Fri, 8 Mar 2013 15:21:51 +0100 [thread overview]
Message-ID: <B3006DF47FCC4C54A55FD4B571F49F5C@erratique.ch> (raw)
In-Reply-To: <CAOOOohTw2dG0MYwuDSvyX0Cxh9Xd_3ekNEaCZhgiztxOOFfd8Q@mail.gmail.com>
Hello,
Le vendredi, 8 mars 2013 à 10:43, Philippe Veber a écrit :
> val bind_s : 'a React.signal -> ('a -> 'b React.signal) -> 'b React.signal
I guess the semantics you want is : [bind_s s sf]_t = [sf [s]_t]_t.
Well that doesn't seem unreasonable. I remember having pondered a lot about which switching combinators to take in the interface and I'm sure I must have considered at least :
switch_s : 'a signal signal -> 'a signal
(* [switch ss]_t = [[ss]_t]_t *)
that would allow for a very easy implementation of bind (switch_s (S.map f s)).
But if it didn't make it *may* be due to thorny signal initialization problems. If you look the signature of the current switch it's a way to force you to have to give an initial value. But a signal, once created, is supposed to have a value at each point in time, well with dynamic switching there are fine points to consider that I don't have in my head right now.
> 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?
As a rule of thumb using S.value is never safe if you are inside an update cycle, this means that you may get problems if you use bind_s during an update cycle itself. Now sometimes it may be hard to find a counter example, as it may be hidden in the messy mechanisms needed to support fixed point combinators and dynamic signal creation. I guess the problem would likely arise if s is itself created during the update cycle, in some cases it could not be initialized yet.
It's a little bit irritating as what you want seems really sound to me, but I'm afraid you cannot implement it with the current interface without providing an initial value yourself.
I don't have the time to investigate right now but I'll surely get back to it later to give you a definitive answer.
Daniel
P.S.
If switch_s can be implemented without problems I'll gladly incorporate it into as *the* S.switch, since the current S.switch would then just be:
sswitch (S.hold s es)
If you are interested you may want to have a look at react's imperative hell to see if it seems workable. Especially by considering/transforming the current S.switch combinator.
next prev parent reply other threads:[~2013-03-08 14:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-08 9:43 Philippe Veber
2013-03-08 11:51 ` Lukasz Stafiniak
2013-03-08 13:55 ` Philippe Veber
2013-03-08 14:21 ` Daniel Bünzli [this message]
2013-03-08 15:02 ` Daniel Bünzli
2013-03-08 22:21 ` Philippe Veber
2013-03-08 22:17 ` Philippe Veber
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=B3006DF47FCC4C54A55FD4B571F49F5C@erratique.ch \
--to=daniel.buenzli@erratique.ch \
--cc=caml-list@inria.fr \
--cc=philippe.veber@gmail.com \
/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