Safe Haskell | None |
---|---|
Language | Haskell98 |
Re-exported and renamed definitions from FRP.Elerea.Simple.
- data Signal a :: * -> *
- data SignalGen a :: * -> *
- execute :: IO a -> SignalGen a
- external :: a -> IO (SignalGen (Signal a), a -> IO ())
- start :: SignalGen (Signal a) -> IO (IO a)
- class MonadFix m => MonadSignalGen m where
- delayS :: MonadSignalGen m => a -> Signal a -> m (Signal a)
- generatorS :: MonadSignalGen m => Signal (SignalGen a) -> m (Signal a)
- snapshotS :: MonadSignalGen m => Signal a -> m a
- memoS :: MonadSignalGen m => Signal a -> m (Signal a)
- transferS :: MonadSignalGen m => a -> (t -> a -> a) -> Signal t -> m (Signal a)
Re-exports
A signal represents a value changing over time. It can be
thought of as a function of type Nat -> a
, where the argument is
the sampling time, and the Monad
instance agrees with the
intuition (bind corresponds to extracting the current sample).
Signals and the values they carry are denoted the following way in
the documentation:
s = <<s0 s1 s2 ...>>
This says that s
is a signal that reads s0
during the first
sampling, s1
during the second and so on. You can also think of
s
as the following function:
s t_sample = [s0,s1,s2,...] !! t_sample
Signals are constrained to be sampled sequentially, there is no
random access. The only way to observe their output is through
start
.
Monad Signal | |
Functor Signal | |
Applicative Signal | |
Apply Signal Event Source # | |
Bounded t => Bounded (Signal t) | |
Enum t => Enum (Signal t) | |
Eq (Signal a) | Equality test is impossible. |
Floating t => Floating (Signal t) | |
Fractional t => Fractional (Signal t) | |
Integral t => Integral (Signal t) | |
Num t => Num (Signal t) | |
Ord t => Ord (Signal t) | |
Real t => Real (Signal t) | |
Show (Signal a) | The Show instance is only defined for the sake of Num... |
SignalSet (Signal a) Source # | |
EasyApply (Signal (a -> b)) (Event a) (Event b) Source # | |
A signal generator is the only source of stateful signals. It
can be thought of as a function of type Nat -> a
, where the
result is an arbitrary data structure that can potentially contain
new signals, and the argument is the creation time of these new
signals. It exposes the MonadFix
interface, which makes it
possible to define signals in terms of each other. The denotation
of signal generators happens to be the same as that of signals, but
this partly accidental (it does not hold in the other variants), so
we will use a separate notation for generators:
g = <|g0 g1 g2 ...|>
Just like signals, generators behave as functions of time:
g t_start = [g0,g1,g2,...] !! t_start
The conceptual difference between the two notions is that signals are passed a sampling time, while generators expect a start time that will be the creation time of all the freshly generated signals in the resulting structure.
:: a | initial value |
-> IO (SignalGen (Signal a), a -> IO ()) | the generator to create the signal and an IO function to feed it |
A signal that can be directly fed through the sink function returned. This can be used to attach the network to the outer world. The signal always yields the value last written to the sink at the start of the superstep. In other words, if the sink is written less frequently than the network sampled, the output remains the same during several samples. If values are pushed in the sink more frequently, only the last one before sampling is visible on the output.
Example:
do (gen,snk) <- external 4 smp <- start gen r1 <- smp r2 <- smp snk 7 r3 <- smp snk 9 snk 2 r4 <- smp print [r1,r2,r3,r4]
Output:
[4,4,7,2]
:: SignalGen (Signal a) | the generator of the top-level signal |
-> IO (IO a) | the computation to sample the signal |
Embedding a signal into an IO
environment. Repeated calls to
the computation returned cause the whole network to be updated, and
the current sample of the top-level signal is produced as a
result. This is the only way to extract a signal generator outside
the network, and it is equivalent to passing zero to the function
representing the generator. In general:
replicateM n =<< start <|<<x0 x1 x2 x3 ...>> ...|> == take n [x0,x1,x2,x3,...]
Example:
do smp <- start (stateful 3 (+2)) res <- replicateM 5 smp print res
Output:
[3,5,7,9,11]
MonadSignalGen
class MonadFix m => MonadSignalGen m where Source #
liftSignalGen :: SignalGen a -> m a Source #
MonadSignalGen SignalGen Source # | |
MonadSignalGen m => MonadSignalGen (MaybeT m) Source # | |
(MonadSignalGen m, Monoid w) => MonadSignalGen (WriterT w m) Source # | |
(MonadSignalGen m, Monoid w) => MonadSignalGen (WriterT w m) Source # | |
MonadSignalGen m => MonadSignalGen (StateT s m) Source # | |
MonadSignalGen m => MonadSignalGen (StateT s m) Source # | |
MonadSignalGen m => MonadSignalGen (IdentityT * m) Source # | |
MonadSignalGen m => MonadSignalGen (ExceptT e m) Source # | |
MonadSignalGen m => MonadSignalGen (ReaderT * r m) Source # | |
(MonadSignalGen m, Monoid w) => MonadSignalGen (RWST r w s m) Source # | |
(MonadSignalGen m, Monoid w) => MonadSignalGen (RWST r w s m) Source # | |
Renamed functions
generatorS :: MonadSignalGen m => Signal (SignalGen a) -> m (Signal a) Source #
snapshotS :: MonadSignalGen m => Signal a -> m a Source #
Same as snapshot
snapshotS sig
returns the current value of sig
.