S      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!9The phases every signal goes through during a superstep. ?A signal generator is the only source of stateful signals. It ) can be thought of as a function of type Nat -> a , where the D result is an arbitrary data structure that can potentially contain A new signals, and the argument is the creation time of these new  signals. It exposes the  interface, which makes it @ possible to define signals in terms of each other. Unlike the B simple variant, the denotation of signal generators differs from : that of signals. We will use the following notation for  generators:   g = <|g0 g1 g2 ...|> DJust 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 BThe conceptual difference between the two notions is that signals B 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 dynamic set of actions to update a network without breaking  consistency. A pointer to an update pair. clocked subnetwork superstep ordinary signal =A pair of actions to update a signal in two phases: internal A update without changing the output, finalisation (throwing away  previous state). ;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  instance agrees with the @ intuition (bind corresponds to extracting the current sample). D 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, s15 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 A random access. The only way to observe their output is through  . Embedding a signal into an ! environment. Repeated calls to E the computation returned cause the whole network to be updated, and = the current sample of the top-level signal is produced as a D result. This is the only way to extract a signal generator outside C 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:  P 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] &the generator of the top-level signal %the computation to sample the signal <Auxiliary function used by all the primitives that create a  mutable variable. sampling function aging function 'the mutable variable behind the signal the pool of update actions the signal created The 1 combinator is the elementary building block for E 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. 5The clock signal associated to the generator affects  D 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 D functions of time (natural numbers), the behaviour of delay can be & described by the following function:  % delay x0 s t_start s_clock t_sample  | t_start == t_sample = x0 / | t_start < t_sample = if s_clock t_sample 1 then s (t_sample-1) J else delay x0 s t_start s_clock (t_sample-1) < | otherwise = error "stream doesn't exist yet" +The way signal generators are extracted by  ensures that  the error can never happen. Example (requires the DoRec extension):   do  smp <- start $ do - rec let fib'' = liftA2 (+) fib' fib # fib' <- delay 1 fib'' ! fib <- delay 1 fib'  return fib  res <- replicateM 7 smp  print res Output:  [1,1,2,3,5,8,13]  initial output at creation time the signal to delay the delayed signal ?A reactive signal that takes the value to output from a signal C 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.  " generator << <|x00 x01 x02 ...|> " <|x10 x11 x12 ...|> " <|x20 x21 x22 ...|>  ... ' >> = <| <<x00 x11 x22 ...>> ' <<x00 x11 x22 ...>> ' <<x00 x11 x22 ...>>  ...  |> 0It can be thought of as the following function:  D generator g t_start s_clock t_sample = g t_sample s_clock t_sample It has to live in the  monad, because it needs to C maintain an internal state to be able to cache the current sample D for efficiency reasons. However, this state is not carried between $ samples, therefore start time doesn't matter and can be ignored. E 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.  the signal of generators to run #the signal of generated structures :Memoising combinator. It can be used to cache results of B applicative combinators in case they are used in several places. D Unlike in the simple variant, it is not observationally equivalent  to  in the $ monad, because it only samples its 4 input signal when the associated clock ticks. The memo 7 combinator can be modelled by the following function:  ! memo s t_start s_clock t_sample # | s_clock t_sample = s t_sample < | otherwise = memo s t_start s_clock (t_sample-1) 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,  incurs a small 4 overhead, therefore it should not be used blindly. BAll the functions defined in this module return memoised signals. the signal to cache 4a signal observationally equivalent to the argument =A signal that is true exactly once: the first time the input C signal is true. Afterwards, it is constantly false, and it holds . no reference to the input signal. Note that  always follows D 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):  2 until <<False False True True False True ...>> = L <| <<False False True False False False False False False False ...>> L << --- False True False False False False False False False ...>> L << --- --- True False False False False False False False ...>> L << --- --- --- True False False False False False False ...>> L << --- --- --- --- False True False False False False ...>> L << --- --- --- --- --- True False False False False ...>> L << --- --- --- --- --- --- False False False False ...>>  ...  |> DIt is observationally equivalent to the following expression (which  would hold onto s forever):   until s = global $ do # step <- transfer False (||) s  dstep <- delay False step # memo (liftA2 (/=) step dstep)  Example:   do  smp <- start $ do  cnt <- stateful 0 (+1) ' tick <- until ((>=3) <$> cnt) & return $ liftA2 (,) cnt tick  res <- replicateM 6 smp  print res Output: > [(0,False),(1,False),(2,False),(3,True),(4,False),(5,False)] the boolean input signal =a one-shot signal true only the first time the input is true =Override the clock used in a generator. Note that clocks don't E interact unless one is used in the definition of the other, i.e. it D is possible to provide a fast clock within a generator with a slow @ associated clock. It is equivalent to the following function:  - withClock s g t_start s_clock = g t_start s /For instance, the following equivalence holds: 1 withClock (pure False) (stateful x f) == pure x Equivalent to withClock (pure True), but more efficient. <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 D sink. In other words, if the sink is written less frequently than A the network sampled, the output remains the same during several B samples. If values are pushed in the sink more frequently, only 8 the last one before sampling is visible on the output.  Example:   do  (sig,snk) <- external 4  smp <- start (return sig)  r1 <- smp  r2 <- smp  snk 7  r3 <- smp  snk 9  snk 2  r4 <- smp  print [r1,r2,r3,r4] Output:  [4,4,7,2] initial value )the signal and an IO function to feed it ?An event-like signal that can be fed through the sink function A 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 C the sink is never invoked. The order of elements is reversed, so B the last value passed to the sink is the head of the list. Note  that unlike  . this function only returns a generator to be C used within the expression constructing the top-level stream, and ' this generator can only be used once.  Example:   do  (gen,snk) <- externalMulti  smp <- start gen  r1 <- smp  snk 7  r2 <- smp  r3 <- smp  snk 9  snk 2  r4 <- smp  print [r1,r2,r3,r4] Output:  [[],[7],[],[2,9]] 9a generator for the event signal and the associated sink @A pure stateful signal. The initial state is the first output, A and every subsequent state is derived from the preceding one by C applying a pure transformation. It is affected by the associated  clock like 0: no transformation is performed in the absence ( of a tick; see the example at the top.  Example:   do ( smp <- start (stateful "x" ('x':))  res <- replicateM 5 smp  print res Output: ! ["x","xx","xxx","xxxx","xxxxx"] initial state state transformation =A stateful transfer function. The current input affects the D current output, i.e. the initial state given in the first argument C is considered to appear before the first output, and can never be A observed, and subsequent states are determined by combining the C preceding state with the current output of the input signal using E the function supplied. It is affected by the associated clock like  ;: no transformation is performed in the absence of a tick;  see the example at the top.  Example:   do  smp <- start $ do  cnt <- stateful 1 (+1)  transfer 10 (+) cnt  res <- replicateM 5 smp  print res Output:  [11,13,16,20,25] initial internal state state updater function  input signal A variation of   with two input signals. initial internal state state updater function input signal 1 input signal 2 A variation of   with three input signals. initial internal state state updater function input signal 1 input signal 2 input signal 3 A variation of   with four input signals. initial internal state state updater function input signal 1 input signal 2 input signal 3 input signal 4 :A random signal. It is affected by the associated clock.  Example:   do * smp <- start noise :: IO (IO Double)  res <- replicateM 5 smp  print res Output: c [0.12067753390401374,0.8658877349182655,0.7159264443196786,0.1756941896012891,0.9513646060896676] A random source within the  monad. A printing action within the  monad. 4Error message for unimplemented instance functions.     @The phases every signal goes through during a superstep: before  or after sampling. ?A signal generator is the only source of stateful signals. It ) can be thought of as a function of type Nat -> Signal p -> a, : where the result is an arbitrary data structure that can E potentially contain new signals, the first argument is the creation D time of these new signals, and the second is a globally accessible  input signal. It exposes the  interface, which makes it @ possible to define signals in terms of each other. Unlike the B simple variant, the denotation of signal generators differs from : that of signals. We will use the following notation for  generators:   g = <|g0 g1 g2 ...|> DJust like signals, generators behave as functions of time, but they % can also refer to the input signal:  / g t_start s_input = [g0,g1,g2,...] !! t_start BThe conceptual difference between the two notions is that signals B 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 dynamic set of actions to update a network without breaking  consistency. ;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  instance agrees with the @ intuition (bind corresponds to extracting the current sample). D 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, s15 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 A random access. The only way to observe their output is through  . Embedding a signal into an ! environment. Repeated calls to E the computation returned cause the whole network to be updated, and E the current sample of the top-level signal is produced as a result. E The computation accepts a global parameter that will be distributed A to all signals. For instance, this can be the time step, if we A want to model continuous-time signals. 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.  Example:   do $ smp <- start (stateful 10 (+)) ! res <- forM [5,3,2,9,4] smp  print res Output:  [10,15,18,20,29] &the generator of the top-level signal %the computation to sample the signal <Auxiliary function used by all the primitives that create a  mutable variable. sampling function aging function 'the mutable variable behind the signal the pool of update actions The 1 combinator is the elementary building block for E 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 (-- is undefined):  ( delay x0 s = <| <<x0 s0 s1 s2 s3 ...>> ( <<-- x0 s1 s2 s3 ...>> ( <<-- -- x0 s2 s3 ...>> ( <<-- -- -- x0 s3 ...>>  ...  |> BIt can be thought of as the following function (which should also ' make it clear why the return value is ):  % delay x0 s t_start s_input t_sample  | t_start == t_sample = x0 * | t_start < t_sample = s (t_sample-1) 7 | otherwise = error \"Premature sample!\" +The way signal generators are extracted by  ensures that E the error can never happen. It is also clear that the behaviour of  1 is not affected in any way by the global input. Example (requires the DoRec extension):   do  smp <- start $ do - rec let fib'' = liftA2 (+) fib' fib # fib' <- delay 1 fib'' ! fib <- delay 1 fib'  return fib ) res <- replicateM 7 (smp undefined)  print res Output:  [1,1,2,3,5,8,13] initial output the signal to delay :Memoising combinator. It can be used to cache results of B applicative combinators in case they are used in several places. % It is observationally equivalent to  in the   monad.   memo s = <|s s s s ...|> 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,  incurs a small 4 overhead, therefore it should not be used blindly. BAll the functions defined in this module return memoised signals.  Just like ), it is independent of the global input. signal to memoise ?A reactive signal that takes the value to output from a signal C 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.  " generator << <|x00 x01 x02 ...|> " <|x10 x11 x12 ...|> " <|x20 x21 x22 ...|>  ... ' >> = <| <<x00 x11 x22 ...>> ' <<x00 x11 x22 ...>> ' <<x00 x11 x22 ...>>  ...  |> 0It can be thought of as the following function:  D generator g t_start s_input t_sample = g t_sample t_sample s_input It has to live in the  monad, because it needs to C maintain an internal state to be able to cache the current sample D for efficiency reasons. However, this state is not carried between $ samples, therefore start time doesn't matter and can be ignored. D Also, even though it does not make use of the global input 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. *a stream of generators to potentially run =A signal that is true exactly once: the first time the input C signal is true. Afterwards, it is constantly false, and it holds D no reference to the input signal. For instance (assuming the rest  of the input is constantly False):  2 until <<False False True True False True ...>> = L <| <<False False True False False False False False False False ...>> L << --- False True False False False False False False False ...>> L << --- --- True False False False False False False False ...>> L << --- --- --- True False False False False False False ...>> L << --- --- --- --- False True False False False False ...>> L << --- --- --- --- --- True False False False False ...>> L << --- --- --- --- --- --- False False False False ...>>  ...  |> DIt is observationally equivalent to the following expression (which  would hold onto s forever):   until s = do + step <- transfer False (const (||)) s  dstep <- delay False step # memo (liftA2 (/=) step dstep)  Example:   do  smp <- start $ do ! accum <- stateful 0 (+) * tick <- until ((>=10) <$> accum) ( return $ liftA2 (,) accum tick % res <- forM [4,1,3,5,2,8,6] smp  print res Output: K [(0,False),(4,False),(5,False),(8,False),(13,True),(15,False),(23,False)] the boolean input signal =a one-shot signal true only the first time the input is true BThe common input signal that is fed through the function returned  by , unless we are in an ded generator. It is ' equivalent to the following function:  ! input t_start s_input = s_input  Example:   do  smp <- start $ do  sig <- input  return (sig*2) % res <- forM [4,1,3,5,2,8,6] smp  print res Output:  [8,2,6,10,4,16,12] :Embed a generator with an overridden input signal. It is ' equivalent to the following function:  ) embed s g t_start s_input = g t_start s  Example:   do  smp <- start $ do  sig <- input  embed (sig*2) $ do  sig <- input  return (sig+1) % res <- forM [4,1,3,5,2,8,6] smp  print res Output:  [9,3,7,11,5,17,13] <A signal that can be directly fed through the sink function @ returned. This can be used to attach the network to the outer E world. Note that this is optional, as all the input of the network B can be fed in through the global parameter, although that is not % really convenient for many signals. initial value )the signal and an IO function to feed it ?An event-like signal that can be fed through the sink function A returned. The signal carries a list of values fed in since the ' last sampling, 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  : 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. 9a generator for the event signal and the associated sink BA direct stateful transformation of the input. The initial state D is the first output, and every following output is calculated from E the previous one and the value of the global parameter (which might  have been overridden by ).  Example:   do $ smp <- start (stateful "" (:))  res <- forM "olleh~" smp  print res Output: $ ["","o","lo","llo","ello","hello"] initial state state transformation =A stateful transfer function. The current input affects the D current output, i.e. the initial state given in the first argument C is considered to appear before the first output, and can never be B observed. Every output is derived from the current value of the ; input signal, the global parameter (which might have been  overridden by -) and the previous output. It is equivalent  to the following expression: BExample (assuming a delta time is passed to the sampling function  in each step):  1 integral x0 s = transfer x0 (\dt v x -> x+dt*v) Example for using the above:   do ( smp <- start (integral 3 (pure 2)) # res <- replicateM 7 (smp 0.1)  print res Output:  [3.2,3.4,3.6,3.8,4.0,4.2,4.4] initial internal state state updater function  input signal A variation of  with two input signals. initial internal state state updater function input signal 1 input signal 2 !A variation of  with three input signals. initial internal state state updater function input signal 1 input signal 2 input signal 3 "A variation of  with four input signals. initial internal state state updater function input signal 1 input signal 2 input signal 3 input signal 4 #A random signal.  Example:   do * smp <- start noise :: IO (IO Double)  res <- replicateM 5 smp  print res Output: c [0.12067753390401374,0.8658877349182655,0.7159264443196786,0.1756941896012891,0.9513646060896676] $A random source within the  monad. %A printing action within the  monad. 4Error message for unimplemented instance functions. Equality test is impossible. The Show* instance is only defined for the sake of ...  !"#$%% !"#$ !"#$%9The phases every signal goes through during a superstep. &?A signal generator is the only source of stateful signals. It ) can be thought of as a function of type Nat -> a , where the D result is an arbitrary data structure that can potentially contain A new signals, and the argument is the creation time of these new  signals. It exposes the  interface, which makes it D possible to define signals in terms of each other. The denotation E of signal generators happens to be the same as that of signals, but E this partly accidental (it does not hold in the other variants), so 1 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 BThe conceptual difference between the two notions is that signals B 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 dynamic set of actions to update a network without breaking  consistency. ';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  instance agrees with the @ intuition (bind corresponds to extracting the current sample). D 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, s15 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 A random access. The only way to observe their output is through  (. (Embedding a signal into an ! environment. Repeated calls to E the computation returned cause the whole network to be updated, and = the current sample of the top-level signal is produced as a D result. This is the only way to extract a signal generator outside C the network, and it is equivalent to passing zero to the function * representing the generator. In general:  P 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] &the generator of the top-level signal %the computation to sample the signal <Auxiliary function used by all the primitives that create a  mutable variable. sampling function aging function 'the mutable variable behind the signal the pool of update actions the signal created )The )1 combinator is the elementary building block for E 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 (-- is undefined):  ( delay x0 s = <| <<x0 s0 s1 s2 s3 ...>> ( <<-- x0 s1 s2 s3 ...>> ( <<-- -- x0 s2 s3 ...>> ( <<-- -- -- x0 s3 ...>>  ...  |> BIt can be thought of as the following function (which should also ' make it clear why the return value is &):   delay x0 s t_start t_sample  | t_start == t_sample = x0 * | t_start < t_sample = s (t_sample-1) 7 | otherwise = error \"Premature sample!\" +The way signal generators are extracted by * ensures that  the error can never happen. Example (requires the DoRec extension):   do  smp <- start $ do - rec let fib'' = liftA2 (+) fib' fib # fib' <- delay 1 fib'' ! fib <- delay 1 fib'  return fib  res <- replicateM 7 smp  print res Output:  [1,1,2,3,5,8,13]  initial output at creation time the signal to delay the delayed signal *?A reactive signal that takes the value to output from a signal C 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.  " generator << <|x00 x01 x02 ...|> " <|x10 x11 x12 ...|> " <|x20 x21 x22 ...|>  ... ' >> = <| <<x00 x11 x22 ...>> ' <<x00 x11 x22 ...>> ' <<x00 x11 x22 ...>>  ...  |> 0It can be thought of as the following function:  4 generator g t_start t_sample = g t_sample t_sample It has to live in the & monad, because it needs to C maintain an internal state to be able to cache the current sample D for efficiency reasons. However, this state is not carried between $ samples, therefore start time doesn't matter and can be ignored. ?Refer to the longer example at the bottom to see how it can be  used.  the signal of generators to run #the signal of generated structures +:Memoising combinator. It can be used to cache results of B applicative combinators in case they are used in several places. % It is observationally equivalent to  in the &  monad.   memo s = <|s s s s ...|> 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, + incurs a small 4 overhead, therefore it should not be used blindly. BAll the functions defined in this module return memoised signals. the signal to cache 4a signal observationally equivalent to the argument ,=A signal that is true exactly once: the first time the input C signal is true. Afterwards, it is constantly false, and it holds D no reference to the input signal. For instance (assuming the rest  of the input is constantly False):  2 until <<False False True True False True ...>> = L <| <<False False True False False False False False False False ...>> L << --- False True False False False False False False False ...>> L << --- --- True False False False False False False False ...>> L << --- --- --- True False False False False False False ...>> L << --- --- --- --- False True False False False False ...>> L << --- --- --- --- --- True False False False False ...>> L << --- --- --- --- --- --- False False False False ...>>  ...  |> DIt is observationally equivalent to the following expression (which  would hold onto s forever):   until s = do # step <- transfer False (||) s  dstep <- delay False step # memo (liftA2 (/=) step dstep)  Example:   do  smp <- start $ do  cnt <- stateful 0 (+1) ' tick <- until ((>=3) <$> cnt) & return $ liftA2 (,) cnt tick  res <- replicateM 6 smp  print res Output: > [(0,False),(1,False),(2,False),(3,True),(4,False),(5,False)] the boolean input signal =a one-shot signal true only the first time the input is true -<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 D sink. In other words, if the sink is written less frequently than A the network sampled, the output remains the same during several B samples. If values are pushed in the sink more frequently, only 8 the last one before sampling is visible on the output.  Example:   do  (sig,snk) <- external 4  smp <- start (return sig)  r1 <- smp  r2 <- smp  snk 7  r3 <- smp  snk 9  snk 2  r4 <- smp  print [r1,r2,r3,r4] Output:  [4,4,7,2] initial value )the signal and an IO function to feed it .?An event-like signal that can be fed through the sink function A returned. The signal carries a list of values fed in since the & last sampling, 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  -: 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.  Example:   do  (gen,snk) <- externalMulti  smp <- start gen  r1 <- smp  snk 7  r2 <- smp  r3 <- smp  snk 9  snk 2  r4 <- smp  print [r1,r2,r3,r4] Output:  [[],[7],[],[2,9]] 9a generator for the event signal and the associated sink /@A pure stateful signal. The initial state is the first output, A and every subsequent state is derived from the preceding one by ! applying a pure transformation.  Example:   do ( smp <- start (stateful "x" ('x':))  res <- replicateM 5 smp  print res Output: ! ["x","xx","xxx","xxxx","xxxxx"] initial state state transformation 0=A stateful transfer function. The current input affects the D current output, i.e. the initial state given in the first argument C is considered to appear before the first output, and can never be A observed, and subsequent states are determined by combining the C preceding state with the current output of the input signal using  the function supplied.  Example:   do  smp <- start $ do  cnt <- stateful 1 (+1)  transfer 10 (+) cnt  res <- replicateM 5 smp  print res Output:  [11,13,16,20,25] initial internal state state updater function  input signal 1A variation of 0 with two input signals. initial internal state state updater function input signal 1 input signal 2 2A variation of 0 with three input signals. initial internal state state updater function input signal 1 input signal 2 input signal 3 3A variation of 0 with four input signals. initial internal state state updater function input signal 1 input signal 2 input signal 3 input signal 4 4A random signal.  Example:   do * smp <- start noise :: IO (IO Double)  res <- replicateM 5 smp  print res Output: c [0.12067753390401374,0.8658877349182655,0.7159264443196786,0.1756941896012891,0.9513646060896676] 5A random source within the & monad. 6A printing action within the & monad. 4Error message for unimplemented instance functions. Equality test is impossible. 9The Show instance is only defined for the sake of Num... &'()*+,-./0123456'&(-.6)*+,/012345&'()*+,-./0123456@The phases every signal goes through during a superstep: before  or after sampling. 7;A signal generator is the only source of stateful signals. D Internally, computes a signal structure and adds the new variables  to an existing update pool. >A dynamic set of actions to update a network without breaking  consistency. 81A signal can be thought of as a function of type Nat -> a, and  its 6 instance agrees with that intuition. Internally, is ( represented by a sampling computation. 9Embedding a signal into an ! environment. Repeated calls to E the computation returned cause the whole network to be updated, and E the current sample of the top-level signal is produced as a result. E The computation accepts a global parameter that will be distributed A to all signals. For instance, this can be the time step, if we ( want to model continuous-time signals. &the generator of the top-level signal %the computation to sample the signal <Auxiliary function used by all the primitives that create a  mutable variable. sampling function aging function 'the mutable variable behind the signal the pool of update actions :The :4 transfer function emits the value of a signal from E the previous superstep, starting with the filler value given in the  first argument. initial output the signal to delay ;:Memoising combinator. It can be used to cache results of B applicative combinators in case they are used in several places. & Other than that, it is equivalent to . signal to memoise <>A reactive signal that takes the value to output from a monad D carried by its input. It is possible to create new signals in the  monad. *a stream of generators to potentially run =<A signal that can be directly fed through the sink function @ returned. This can be used to attach the network to the outer E world. Note that this is optional, as all the input of the network B can be fed in through the global parameter, although that is not % really convenient for many signals. initial value )the signal and an IO function to feed it >?An event-like signal that can be fed through the sink function A returned. The signal carries a list of values fed in since the ' last sampling, 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  =: 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. 9a generator for the event signal and the associated sink ?@A pure stateful signal. The initial state is the first output, D and every following output is calculated from the previous one and $ the value of the global parameter. @=A stateful transfer function. The current input affects the D current output, i.e. the initial state given in the first argument C is considered to appear before the first output, and can never be B observed. Every output is derived from the current value of the B input signal, the global parameter and the previous output. The E only exception is when a transfer function sits in a loop without a B delay. In this case, a delay will be inserted at a single place D during runtime (i.e. the previous output of the node affected will 0 be reused) to resolve the circular dependency. AA random signal. BA random source within the 7 monad. CA printing action within the 7 monad. 4Error message for unimplemented instance functions. Equality test is impossible. The Show* instance is only defined for the sake of ... 789:;<=>?@ABC 879=>:?@;<ABC 789:;<=>?@ABC2D5The possible structures of a node are defined by the D type. Note that the SNFx# nodes are only needed to optimise 4applicatives, they can all be expressed in terms of SNK and SNA. ESNF5 f: liftA5 f FSNF4 f: liftA4 f GSNF3 f: liftA3 f HSNF2 f: liftA2 f ISNF1 f: fmap f JSNKA s l: equivalent to s while aging signal l KSND s: the s! signal delayed by one superstep LSNE r*: opaque reference to connect peripherals MSNM b sm3: signal generator that executes the monad carried  by sm whenever b% is true, and outputs the result (or  undefined when b is false) NSNH ss r: the higher-order signal ss collapsed into a  signal cached in reference r; r is used during the aging  phase O SNA sf sx!: pointwise function application P SNT s x t1: stateful transfer function, which also depends  on an input signal s QSNS x t: stateful generator, where x is current state and  t is the update function RSNK x : constantly x S?A node can have four states that distinguish various stages of sampling and aging. TAged x s is the aged version of signal s paired with its  current value x U Sampled x s is signal s paired with its current value x V Sampling s is signal s after its current value was " requested, but not yet delivered WReady s is simply the signal s that was not sampled yet X0A signal is conceptually a time-varying value. YZ3A restricted monad to create stateful signals in. [\]BSinks are used when feeding input into peripheral-bound signals. ^%Time is continuous. Nothing fancy. _,A printing function that can be used in the Z. "Provided for debugging purposes. `BYou can uncomment the verbose version of this function to see the &applicative optimisations in action. a5Error message for unimplemented instance functions. b Creating a reference within the Z. Used for stateful  signals. c:Creating a reference as a pure value. Used for stateless  signals. dCSampling the signal and all of its dependencies, at the same time. We don':t need the aged signal in the current superstep, only the Bcurrent value, so we sample before propagating the changes, which Bmight require the fresh sample because of recursive definitions. e;Aging the network of signals the given signal depends on. f-Finalising aged signals for the next round. g?Aging the signal. Stateful signals have their state forced to Bprevent building up big thunks. The other nodes are structurally  static. hASampling the signal at the current moment. This is where static Enodes propagate changes to those they depend on. Transfer functions (P>) work without delay, i.e. the effects of their input signals (can be observed in the same superstep. i@Sampling the signal with some kind of delay in order to resolve Cdependency loops. Transfer functions simply return their previous Eoutput (delays can be considered a special case, because they always  do that, so i) is never called with them), while other +types of signals are always handled by the h function, so it is Bnot possible to create a working stateful loop composed of solely stateless combinators. j@Advancing the whole network that the given signal depends on by 2the amount of time given in the second argument. the top-level signal the amount of time to advance  the current value of the signal kAA pure stateful signal. The initial state is the first output. initial state state transformation l=A stateful transfer function. The current input affects the Fcurrent output, i.e. the initial state given in the first argument is Gconsidered to appear before the first output, and can only be directly observed by the i function. initial internal state state updater function  input signal m<A continuous sampler that flattens a higher-order signal by #outputting its current snapshots. signal to flatten n>A reactive signal that takes the value to output from a monad Fcarried by its input when a boolean control signal is true, otherwise  it outputs /. It is possible to create new signals in the )monad and also to print debug messages. control (trigger) signal &a stream of monads to potentially run o)A helper function to wrap any value in a  depending on a boolean condition. p<A signal that can be directly fed through the sink function ?returned. This can be used to attach the network to the outer world. initial value )the signal and an IO function to feed it qThe q8 transfer function emits the value of a signal from the Fprevious superstep, starting with the filler value given in the first Gargument. It has to be a primitive, otherwise it could not be used to prevent automatic delays. initial output the signal to delay r@Dependency injection to allow aging signals whose output is not >necessarily needed to produce the current sample of the first  argument. It's equivalent to (flip . liftA2 . flip) const, as it &evaluates its second argument first. the actual output 4a signal guaranteed to age when this one is sampled GThe equality test checks whether two signals are physically the same. The Show* instance is only defined for the sake of ... The + instance with run-time optimisation. The  Goperator tries to move all the pure parts to its left side in order to Hflatten the structure, hence cutting down on book-keeping costs. Since Dapplicatives are used with pure functions and lifted values most of 6the time, one can gain a lot by merging these nodes. /DEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr/^]Z[\_XYSWVUTDRQPONMLKJIHGFE`abcdefghijklmnopqr/DRQPONMLKJIHGFEEFGHIJKLMNOPQRSWVUTTUVWXYYZ[\[\]^_`abcdefghijklmnopqrsETraversing the network starting from the given signal and converting 2it into a string containing the graph in Graphviz ( http://www.graphviz.org/+) dot format. Stateful nodes are coloured according to their type. FThe results might differ depending on whether this function is called Fbefore or after sampling (this also affects the actual network!), but )the networks should be still equivalent. sss tA short alternative name for r. uThe u9 transfer function takes a bool signal and emits another Fbool signal that turns true only at the moment when there is a rising edge on the input. vThe v+ transfer function behaves as a latch on a  ,input: it keeps its state when the input is , and replaces it with the input otherwise. Initial output Maybe signal to latch on w%Point-wise equality of two signals. x'Point-wise inequality of two signals. y'Point-wise comparison of two signals. z'Point-wise comparison of two signals. {'Point-wise comparison of two signals. |'Point-wise comparison of two signals. }'Point-wise OR of two boolean signals. ~(Point-wise AND of two boolean signals. XZ\]^_jklmnopqrtuvwxyz{|}~^]XZ\\jpklqmnvourtwxyz{|~}_ tuvwxyz{|}~                     !"#$%&'()*+,-./01 23456789:;<=>?@ABCD E FGHIJKLMNOPQRST1UVWXYZ[\]^U_`2abcdeU_f:S.1XYZ2e:ghUijST1XYZ2e:ghS.01XYZ2ke:ghUlmUlnghoUpqUprstuvwxyz{|}~ elerea-2.3.0FRP.Elerea.ClockedFRP.Elerea.ParamFRP.Elerea.SimpleFRP.Elerea.Legacy.DelayedFRP.Elerea.Legacy.InternalFRP.Elerea.Legacy.GraphFRP.Elerea.Legacy FRP.Elerea SignalGenSignalstartdelay generatormemountil withClockglobalexternal externalMultistatefultransfer transfer2 transfer3 transfer4noise getRandomdebuginputembed SignalNodeSNF5SNF4SNF3SNF2SNF1SNKASNDSNESNMSNHSNASNTSNSSNK SignalTransAgedSampledSamplingReadyS SignalMonadSM createSignalSinkDTime signalDebugdebugLogunimp makeSignalmakeSignalUnsafe signalValueagecommitadvancesample sampleDelayed superstepsamplertoMaybe keepAlive signalToDot.@.edge storeJust==@/=@<@<=@>=@>@||@&&@PhaseUpdatedbaseControl.Monad.FixMonadFixSGunSG UpdatePoolUpdateUClkUSig UpdateActionGHC.BaseMonad getUpdateghc-prim GHC.TypesIO addSignalreturn $fEqSignal $fShowSignalGHC.NumNumunS Data.MaybeNothingMaybe$fApplicativeSignalControl.Applicative Applicative<*> SignalInfoNoneLift5Lift4Lift3Lift2Lift1DelayExternal GeneratorSamplerAppTransferStatefulConst SignalStoreIdgetPtr buildStore insertSignal nodeLabel