1 {-# LANGUAGE Arrows #-}
16 infinity :: (Fractional a) => a
19 -- Outputs the average time between ivlNum of the last events. Goes to
20 -- infinity if less than ivlNum events have occured or if no event has
21 -- occured in maxTime.
22 avgIvl :: SF (Event a) DTime
23 avgIvl = switch (constant infinity &&& constant (Event [])) avgIvl'
25 avgIvl' l = switch avgIvl'' (avgIvl')
26 where avgIvl'' :: SF (Event a) (DTime, Event [DTime])
27 avgIvl'' = proc e -> do
30 tooLate <- after maxTime [] -< ()
31 let timeList = (e' `tag` (appDTime ivlNum t l)) `lMerge` tooLate
32 returnA -< (avgS ivlNum l, timeList)
34 appDTime :: Int -> Time -> [DTime] -> [DTime]
36 appDTime n t l = t:(take (n-1) l)
38 avgS :: (Fractional a) => Int -> [a] -> a
40 | length l /= n = infinity
41 | otherwise = foldl (+) 0 l / fromIntegral n