Copyright | (c) Ivan Perez 2019-2022 (c) Ivan Perez and Manuel Baerenz 2016-2018 |
---|---|
License | BSD3 |
Maintainer | ivan.perez@keera.co.uk |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Event Signal Functions and SF combinators.
Events represent values that only exist instantaneously, at discrete points in time. Examples include mouse clicks, zero-crosses of monotonic continuous signals, and square waves.
For signals that carry events, there should be a limit in the number of events we can observe in a time period, no matter how much we increase the sampling frequency.
Synopsis
- never :: Monad m => SF m a (Event b)
- now :: Monad m => b -> SF m a (Event b)
- after :: Monad m => Time -> b -> SF m a (Event b)
- repeatedly :: Monad m => Time -> b -> SF m a (Event b)
- afterEach :: Monad m => [(Time, b)] -> SF m a (Event b)
- afterEachCat :: Monad m => [(Time, b)] -> SF m a (Event [b])
- delayEvent :: Monad m => Time -> SF m (Event a) (Event a)
- delayEventCat :: Monad m => Time -> SF m (Event a) (Event [a])
- edge :: Monad m => SF m Bool (Event ())
- iEdge :: Monad m => Bool -> SF m Bool (Event ())
- edgeTag :: Monad m => a -> SF m Bool (Event a)
- edgeJust :: Monad m => SF m (Maybe a) (Event a)
- edgeBy :: Monad m => (a -> a -> Maybe b) -> a -> SF m a (Event b)
- notYet :: Monad m => SF m (Event a) (Event a)
- once :: Monad m => SF m (Event a) (Event a)
- takeEvents :: Monad m => Int -> SF m (Event a) (Event a)
- dropEvents :: Monad m => Int -> SF m (Event a) (Event a)
- snap :: Monad m => SF m a (Event a)
- snapAfter :: Monad m => Time -> SF m a (Event a)
- sample :: Monad m => Time -> SF m a (Event a)
- sampleWindow :: Monad m => Int -> Time -> SF m a (Event [a])
- recur :: Monad m => SF m a (Event b) -> SF m a (Event b)
- andThen :: Monad m => SF m a (Event b) -> SF m a (Event b) -> SF m a (Event b)
Basic event sources
now :: Monad m => b -> SF m a (Event b) Source #
Event source with a single occurrence at time 0. The value of the event is given by the function argument.
:: Monad m | |
=> Time | The time q after which the event should be produced |
-> b | Value to produce at that time |
-> SF m a (Event b) |
Event source with a single occurrence at or as soon after (local) time q as possible.
repeatedly :: Monad m => Time -> b -> SF m a (Event b) Source #
Event source with repeated occurrences with interval q.
Note: If the interval is too short w.r.t. the sampling intervals, the result will be that events occur at every sample. However, no more than one event results from any sampling interval, thus avoiding an "event backlog" should sampling become more frequent at some later point in time.
afterEach :: Monad m => [(Time, b)] -> SF m a (Event b) Source #
Event source with consecutive occurrences at the given intervals. Should more than one event be scheduled to occur in any sampling interval, only the first will in fact occur to avoid an event backlog.
afterEachCat :: Monad m => [(Time, b)] -> SF m a (Event [b]) Source #
Event source with consecutive occurrences at the given intervals. Should more than one event be scheduled to occur in any sampling interval, the output list will contain all events produced during that interval.
delayEvent :: Monad m => Time -> SF m (Event a) (Event a) Source #
Delay for events. (Consider it a triggered after, hence basic.)
delayEventCat :: Monad m => Time -> SF m (Event a) (Event [a]) Source #
Delay an event by a given delta and catenate events that occur so closely so as to be inseparable.
edge :: Monad m => SF m Bool (Event ()) Source #
A rising edge detector. Useful for things like detecting key presses. It is initialised as up, meaning that events occurring at time 0 will not be detected.
edgeTag :: Monad m => a -> SF m Bool (Event a) Source #
Like edge
, but parameterized on the tag value.
edgeBy :: Monad m => (a -> a -> Maybe b) -> a -> SF m a (Event b) Source #
Edge detector parameterized on the edge detection function and initial state, i.e., the previous input sample. The first argument to the edge detection function is the previous sample, the second the current one.
Stateful event suppression
notYet :: Monad m => SF m (Event a) (Event a) Source #
Suppression of initial (at local time 0) event.
takeEvents :: Monad m => Int -> SF m (Event a) (Event a) Source #
Suppress all but the first n events.
Hybrid SF combinators
snap :: Monad m => SF m a (Event a) Source #
Event source with a single occurrence at time 0. The value of the event is obtained by sampling the input at that time.
snapAfter :: Monad m => Time -> SF m a (Event a) Source #
Event source with a single occurrence at or as soon after (local) time
tEv
as possible. The value of the event is obtained by sampling the input a
that time.
sampleWindow :: Monad m => Int -> Time -> SF m a (Event [a]) Source #
Window sampling.
First argument is the window length wl, second is the sampling interval t. The output list should contain (min (truncate (T/t) wl)) samples, where T is the time the signal function has been running. This requires some care in case of sparse sampling. In case of sparse sampling, the current input value is assumed to have been present at all points where sampling was missed.