Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FRP (reactive): How to use filterE?

Tags:

haskell

frp

I expect the next will print "()" 10 times in a second. But it hangs after a second. Why?

adaptE $ fmap print $ filterE (const True) $ atTimes [0.1, 0.2 ..]

I found that it is related to liftM used in filterE:

filterE :: (Ord t, Bounded t) => (a -> Bool) -> EventG t a -> EventG t a
filterE p m = justE (liftM f m)
 where
   f a | p a        = Just a
       | otherwise  = Nothing

I tried to reimplement filterE using fmap and it seems to work. Why? How the standard filterE is designed to be used?

I found myself reimplementing a lot of standard functions provided by the reactive package (e.g. diffE, integrate). Does it mean that the package is buggy or I use it in a wrong way?

Thanks!

like image 312
Yuras Avatar asked Nov 06 '10 13:11

Yuras


1 Answers

In my experience reactive is buggy, especially with regard to the Monad instance of Event (the monad join operation is slightly too strict and we're not exactly sure why). Avoid that if possible. Reactive was an experiment, and represents what might be possible with more runtime support. See Yampa for a more stable, reliable, and well-traveled FRP library, even if it is a bit less expressive.

like image 161
luqui Avatar answered Oct 22 '22 06:10

luqui