我期望下面的代码每秒钟会打印出10次"()"。但是它在一秒钟后就停止了。为什么呢?
adaptE $ fmap print $ filterE (const True) $ atTimes [0.1, 0.2 ..]
我发现这与在 filterE 中使用的 liftM 有关:
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
我尝试使用
fmap
重新实现filterE
,似乎可以正常工作。为什么呢?
标准的filterE
应该如何使用?我发现自己不得不重新实现许多由
reactive
包提供的标准函数(例如diffE
,integrate
)。这是意味着该包存在缺陷还是我使用方法错误?谢谢!
adaptE . fmap print $ atTimes [0.1, 0.2 .. 10]
可以在10秒内运行,而adaptE . liftM print $ atTimes [0.1, 0.2 .. 10]
永远不会返回。为什么? - Yuras