1 {-# LANGUAGE Arrows #-}
3 module RMCA.Auxiliary.Auxiliary where
8 -- stepBack contains its previous argument as its output. Because it's
9 -- hard to define it at time 0, it's wrapped up in a Maybe.
10 stepBack :: SF a (Maybe a)
11 stepBack = sscan f (Nothing, Nothing) >>^ snd
12 where f :: (Maybe a, Maybe a) -> a -> (Maybe a, Maybe a)
13 f (Nothing,_) x' = (Just x', Nothing)
14 f (Just x, _) x' = (Just x', Just x)
16 -- Just like stepBack but the output value is always defined and is
17 -- equal to the input at time 0.
19 stepBack' = proc x -> do
21 returnA -< fromMaybe x x'
23 -- Throws an Event when the incoming signal change. The Event is
24 -- tagged with the new value.
25 onChange :: (Eq a) => SF a (Event a)
26 onChange = proc x -> do
28 returnA -< makeEvent x x'
30 -- Similar to onChange but contains its initial value in the first
32 onChange' :: (Eq a) => SF a (Event a)
33 onChange' = proc x -> do
35 returnA -< makeEvent x x'
37 makeEvent :: (Eq a) => a -> Maybe a -> Event a
39 | isNothing x' = Event x
40 | otherwise = let x'' = fromJust x' in
41 if x'' == x then NoEvent else Event x
46 bound :: (Ord a) => (a, a) -> a -> a