[Haskell-beginners] FRP

Miguel Negrao miguel.negrao-lists at friendlyvirus.org
Thu Sep 27 13:58:50 CEST 2012


A 20/09/2012, às 03:56, Ertugrul Söylemez escreveu:

> Miguel Negrao <miguel.negrao-lists at friendlyvirus.org> wrote:
> 
>>> Netwire follows a more algebraic path and drops the classic notion.
>>> The line between signals and events is blurred.  It's a bit more
>>> difficult to understand, but is more expressive and concise.  Also
>>> it's pretty much time-leak-free.  The library is designed to be very
>>> elegant while preserving non-FRP performance to a high degree.
>>> 
>>> (To be fair, I'm the author of Netwire.) =)
>> 
>> Having recently looked a bit on Yampa, what are the main differences
>> between Yampa and Netwire ?
> 
> The way events are handled.  Yampa uses the classic automaton category
> with an additional time delta argument for its signal function [...]


Thanks for the explanation. I was wondering, how would one translate this Yampa code into reactive-banana:

fallingBall :: Pos -> Vel -> SF () (Pos, Vel)
	fallingBall y0 v0 = proc () -> do
		v <- (v0 +) ˆ<< integral -< -9.81
		y <- (y0 +) ˆ<< integral -< v
		returnA -< (y, v)

fallingBall’ :: Pos -> Vel -> SF () ((Pos,Vel), Event (Pos,Vel))
fallingBall’ y0 v0 = proc () -> do
	yv@(y, _) <- fallingBall y0 v0 -< ()
	hit <- edge -< y <= 0
	returnA -< (yv, hit ‘tag‘ yv)

bouncingBall :: Pos -> SF () (Pos, Vel)
bouncingBall y0 = bbAux y0 0.0
	where
		bbAux y0 v0 = switch (fallingBall’ y0 v0) $ \(y,v) -> bbAux y (-v)

Would it be possible to do this without dynamic event switching ? What about with the new event switching in v0.7 ?  Also, is it possible (and is it easy ?) to do looping such as it is done in Yampa using the the loop arrow in reactive-banana/classic FRP ?

best,
Miguel Negrão


More information about the Beginners mailing list