Good point. There is already a VectorSpace instance for behaviors, and using it in the positionB definition makes for a much more general type. See FRP.Reactive.VectorSpace.
I wouldn't use v ^* t (or t *^ v), however, because v is dynamic. Integrating v ought to do the trick.
And I expect that any simple & direct formulation will run into the current implementation bug with recursive behaviors, since the position depends on the velocity, the velocity depends on acceleration and accumulated impulse, and the accumulated impulse depends on position.
- Conal
Shouldn't Reactive also have VectorSpace instances for Behaviors of VectorSpace elements? So that the code becomes> positionB x0 v t = pure x0 ^+^ v ^* tMaybe it already has, in that case, sorry for the spam ;)
On Fri, Nov 21, 2008 at 7:00 PM, Greg Fitzgerald <garious@gmail.com> wrote:
>>> positionB :: Double -> Behavior Double -> Behavior Double -> Behavior Double
>>> positionB x0 v t = (x0 +) <$> liftA2 (*) v t
> positionB x0 v t = pure x0 + v * tThat's very convenient. I'm showing this stuff off to visual
designers, so tricks like this have great Sales appeal. :)
If others are trying this out, the Num instance is implemented in
FRP.Reactive.Num.
-Greg
On Fri, Nov 21, 2008 at 6:48 AM, Conal Elliott <conal@conal.net> wrote:
> For that matter, you can also say, thanks to Num overloading:
>
> positionB :: Double -> Behavior Double -> Behavior Double -> Behavior Double
> positionB x0 v t = pure x0 + v * t
>
> Sadly, similar convenience does not come for free with non-methods, such as
> most of the FieldTrip API. For non-methods, in the past (with Fran), I've
> written parallel sets of modules with behavior-lifted functionality. It's
> tedious to set up but convenient to use. Perhaps a tool could automate the
> job.
>
> By the way, a nice feature of Yampa is that it avoids this lifting business
> altogether, via desugaring for the arrow notation.
>
> - Conal
>
> On Fri, Nov 21, 2008 at 12:14 AM, Thomas Davie <tom.davie@gmail.com> wrote:
>>>
>>> positionB :: Double -> Behavior Double -> Behavior Double -> Behavior
>>> Double
>>> positionB x0 v t = (x0 +) <$> liftA2 (*) v t
>>
>> On an unrelated note, I created a package called InfixApplicative, because
>> I found that exactly this kind of expression looked ugly in my code. If you
>> import it, you can define this instead:
>>
>> positionB x0 v t = (x0 +) <$> (v <^(*)^> t)
>>
>> Hope that helps
>>
>> Bob
>> _______________________________________________
>> Reactive mailing list
>> Reactive@haskell.org
>> http://www.haskell.org/mailman/listinfo/reactive
>
>
_______________________________________________
Reactive mailing list
Reactive@haskell.org
http://www.haskell.org/mailman/listinfo/reactive