My network looks like this:
ePhysics :: Event t ()
bPlayerForce :: Behavior t (Double,Double)
bPlayerPosition :: Behavior t (Double, Double)
ePhysics
is fired repeatedly from a timer.
I'm having issues with defining bPlayerPosition
. What I intend is that it will start at (0,0)
, and whenever ePhysics
is fired, bPlayerPosition
will be recalculated using bPlayerForce
as a parameter.
The problem is that in-order to specify an initial value I need to use accumB
/stepper
but they only work with events, and I can't get the force value from bPlayerForce
since only behaviors can get the value of other behaviors (with <*>
).
The alternative would be just using <*>
but with that I have no initial value, so it becomes a meaningless infinite recursion:
let bPlayerPosition = pure calcPosition <*> bPlayerForce <*> bPlayerPosition
I have 3 questions:
- Is there a way of getting a value out of a behavior without
<*>
? like, whenreactimate
ing or mapping an event? the issue of not being able to has been screwing with me constantly since the very start. - Would there be a more functional/frp way to do physics? (in general and the ones specific to the question)
- How can I solve the presented problem?
apply
, a.k.a.(<@>)
– Lydaintegral :: (VectorSpace v) => Behavior v -> Behavior v
, which reactive-banana does not provide, but which can be approximated (in essentially the way you describe here, but the meaning is the important thing!). – Lydaapply
? I mean, I don't have any event relevant for its argument. If reactive-banana isn't 100% perfectly suited for the task could you please suggest an FRP library that would be more complete for me (and hopefully one withintegral
you mentioned)? – Sitar