This version differs from the simple one in adding associated freeze
control signals ('clocks') to stateful entities to be able to pause
entire subnetworks without having to write all the low-level logic
explicitly. The clocks are fixed to signals upon their creation, and
the withClock function can be used to specify the common clock for
the signals created in a given generator.

A clock signal affects delay elements the following way: if the
clock signal is true, the delay works as usual, otherwise it remembers
its current output and throws away its current input. If we consider
signals to be functions of time (natural numbers), the behaviour of
delay can be described by the following function:

The problem is that the clocks are also slowed down, and their spikes
double in length. This may or may not be what you want. To overcome
this problem, we can define a clock oblivious edge detector to be used
within the definition of drift:

The signal abstraction

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.

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. Unlike the
simple variant, the denotation of signal generators differs from
that of signals. We will use the following notation for
generators:

g = <|g0 g1 g2 ...|>

Just like signals, generators behave as functions of time, but they
can also refer to the clock signal:

g t_start s_clock = [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.

Embedding into I/O

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. The clock associated with the
top-level signal ticks at every sampling point. In general:

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. 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.

An event-like signal that can be fed through the sink function
returned. The signal carries a list of values fed in since the
last sampling (always synchronised to the top-level samplings
regardless of any associated clock), i.e. it is constantly [] if
the sink is never invoked. The order of elements is reversed, so
the last value passed to the sink is the head of the list. Note
that unlike external this function only returns a generator to be
used within the expression constructing the top-level stream, and
this generator can only be used once.

Basic building blocks

The delay combinator is the elementary building block for
adding state to the signal network by constructing delayed versions
of a signal that emit a given value at creation time and the
previous output of the signal afterwards.

The clock signal associated to the generator affects delay
elements the following way: if the clock signal is true, the delay
works as usual, otherwise it remembers its current output and
throws away its current input. If we consider signals to be
functions of time (natural numbers), the behaviour of delay can be
described by the following function:

A formal conversion from signals to signal generators, which
effectively allows for retrieving the current value of a previously
created signal within a generator. This includes both signals
defined in an external scope as well as those created earlier in
the same generator. It can be modelled by the following function:

A reactive signal that takes the value to output from a signal
generator carried by its input with the sampling time provided as
the start time for the generated structure. It is possible to
create new signals in the monad, which is the key to defining
dynamic data-flow networks.

It has to live in the SignalGen monad, because it needs to
maintain an internal state to be able to cache the current sample
for efficiency reasons. However, this state is not carried between
samples, therefore start time doesn't matter and can be ignored.
Also, even though it does not make use of the clock itself, part of
its job is to distribute it among the newly generated signals.

Refer to the longer example at the bottom of FRP.Elerea.Simple to
see how it can be used.

Memoising combinator. It can be used to cache results of
applicative combinators in case they are used in several places.
Unlike in the simple variant, it is not observationally equivalent
to return in the SignalGen monad, because it only samples its
input signal when the associated clock ticks. The memo
combinator can be modelled by the following function:

For instance, if s = f <$> s', then f will be recalculated
once for each sampling of s. This can be avoided by writing s
<- memo (f <$> s') instead. However, memo incurs a small
overhead, therefore it should not be used blindly.

A signal that is true exactly once: the first time the input
signal is true. Afterwards, it is constantly false, and it holds
no reference to the input signal. Note that until always follows
the master clock, i.e. the fastest one, therefore it never creates
a long spike of True. For instance (assuming the rest of the
input is constantly False):

Override the clock used in a generator. Note that clocks don't
interact unless one is used in the definition of the other, i.e. it
is possible to provide a fast clock within a generator with a slow
associated clock. It is equivalent to the following function:

Derived combinators

A pure stateful signal. The initial state is the first output,
and every subsequent state is derived from the preceding one by
applying a pure transformation. It is affected by the associated
clock like delay: no transformation is performed in the absence
of a tick; see the example at the top.

A stateful transfer function. The current input affects the
current output, i.e. the initial state given in the first argument
is considered to appear before the first output, and can never be
observed, and subsequent states are determined by combining the
preceding state with the current output of the input signal using
the function supplied. It is affected by the associated clock like
delay: no transformation is performed in the absence of a tick;
see the example at the top.

In essence, this combinator provides cooperative multitasking
capabilities, and its primary purpose is to assist library writers
in wrapping effectful APIs as conceptually pure signals. If there
are several effectful signals in the system, their order of
execution is undefined and should not be relied on.