-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Behavior a -> Event b -> Dynamic a
please?
#140
Comments
I've wanted this before as well. But I'm not sure there is a "safe" way of doing it (that doesn't suffer from high likelihood of cycles or being wrong). |
@lspitzner What are the semantics you're looking for? E.g.: if we produce |
I would imagine |
I thought about these some more, and I think these functions can't be written. In the case of So, I believe that the only acceptable implementation for this function involves supplying Note that this argument makes critical use of the Dynamic law, so, as you might expect, For |
What if |
The function with that exact type signature is
|
Aha! Thank you. I did notice that |
FWIW, I've found that |
It's aptly named. I don't think I'd ever dare to use it. |
@ryantrinkle Right. What about the versions that return monadic values? Are the following bad idea? (The names may be chosen badly, and I dislike the RankNTypes, but otherwise?) dynamicPushAlways1
:: (R.Reflex t, R.MonadHold t m)
=> R.Dynamic t a
-> (forall m' . R.MonadSample t m' => a -> m' b)
-> m (R.Dynamic t b)
dynamicPushAlways1 ad f =
R.buildDynamic (f =<< R.sample (R.current ad)) (R.pushAlways f (R.updated ad))
dynamicPushAlways2
:: (R.Reflex t, R.MonadHold t m, MonadFix m)
=> R.Dynamic t a
-> (forall m' . (R.MonadHold t m', MonadFix m') => a -> m' b)
-> m (R.Dynamic t b)
dynamicPushAlways2 ad f = do
b0 <- f =<< R.sample (R.current ad)
R.foldDynM (\a _ -> f a) b0 (R.updated ad)
dynamicAttachWith
:: (R.Reflex t, R.MonadHold t m)
=> (a -> b -> c)
-> R.Behavior t a
-> R.Dynamic t b
-> m (R.Dynamic t c)
dynamicAttachWith f ab bd = do
a0 <- R.sample ab
b0 <- R.sample (R.current bd)
R.holdDyn (f a0 b0)
(R.pushAlways (\b -> R.sample ab <&> \a -> f a b) (R.updated bd))
dynamicTag
:: (R.Reflex t, R.MonadHold t m)
=> R.Behavior t a
-> R.Event t b
-> m (R.Dynamic t a)
dynamicTag ab be = do
a0 <- R.sample ab
R.holdDyn a0 (R.pushAlways (\_ -> R.sample ab) be) (edit 1: removed some unnecessary constraints, make dynamicTag use |
@lspitzner Can you provide some examples of the situations where these would be used? |
No, not really :/ Most of the time one can invent some initial values so creating a Dynamic from some pushAlways'd Event is trivial. I'll have to look out for some good examples. |
My general sense is that, if I found myself needing
|
Really i was looking for
(a -> b -> c) -> Behavior a -> Dynamic b -> Dynamic c
. Both are expressible via some combination ofupdated
,attachWith
,current
,sample
andbuildDynamic
, but i'd prefer something a bit higher-level.(i base this mostly on the quickref, so perhaps i am missing something that isn't there.)
The text was updated successfully, but these errors were encountered: