-
Notifications
You must be signed in to change notification settings - Fork 71
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
Generalize <@> #181
Comments
As a motivating example, here's a simple first-order rendering of some widgets: -- render event and rendering function
eRender :: Event ()
render :: [Widget] -> IO () bScene :: Behavior [Widget]
reactimate (render <$> bScene <@ eRender) Now say the widgets themselves are dynamic, so we move to higher-order combinators: bScene :: Behavior [Behavior Widget]
reactimate (render <$> observeE ((valueB . sequenceA) <$> bScene <@ eRender)) This is the version I'd like to clean up, somehow, because I find it very difficult to read and understand. One observation is that everything is much simpler in the Instead of the above, I could drill down into the time-varying mScene :: Moment [Widget]
mScene = do
bWidgets <- valueB bScene
valueB (sequenceA bWidgets) The very last step of "sampling a time-varying thing when an event occurs" is where I could benefit from reactimate (render <$> mScene <@ eRender) But instead, I have to write: reactimate (render <$> observeE (mScene <$ eRender)) |
The term |
Personally I think using
I would write this as: reactimate $ observeE $ eRender $> do
bWidgets <- valueB $ sequenceA bScene
widgets <- valueB bWidgets
return $ render widgets @mitchellwrosen I'm generally pretty averse to type classes just for overloading. Is this something you strongly desire, or do you think using |
@ocharles Good question... I too am generally averse to ad-hoc overloading, and it would also be nice not to make a beginner's first-order FRP experience more complicated in service of a power user who can wrangle higher-order FRP. (Note: that ship has begun to sail anyway with the inclusion of Moment in the type of accumB) That said, I feel the semantics and similarity between Moment and Behavior is captured very well by the generalization of Moment and Behavior are in fact both conceptually identical - a value that varies over time. Such a thing can be sampled whenever an event fires at a particular moment in time - that's The difference between Moment and Behavior only leaks through in combinators like |
When doing higher-order FRP, the
Moment
concept comes up often. It's similar toBehavior
in that aMoment a
represents ana
that has a value at every point in time. (Aside: more documentation about this concept would be helpful; in the "model" implementation,Moment
andBehavior
are isomorphic, which is confusing).For this reason I wonder if the
<@>
could/should be generalized to address both of these uses:The text was updated successfully, but these errors were encountered: