-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Generic automaton arrow transformer and useful tools
--
-- This library implements a powerful generic automaton arrow
-- transformer.
@package netwire
@version 2.0.1
-- | This module defines Functor, Applicative,
-- Alternative, Monad and MonadPlus instances for
-- First and Last monoids.
module Control.Wire.Instances
instance MonadPlus Last
instance Monad Last
instance Alternative Last
instance Applicative Last
instance Functor Last
instance MonadPlus First
instance Monad First
instance Alternative First
instance Applicative First
instance Functor First
-- | Utilities for creating wires.
module Control.Wire.Tools
-- | Distribute an input value over a list of arrow computations and
-- collect the results.
distA :: Arrow >~ => [a >~ b] -> (a >~ [b])
-- | Lift an arrow computation to lists of values.
mapA :: ArrowChoice >~ => (a >~ b) -> ([a] >~ [b])
-- | Type classes used in Netwire.
module Control.Wire.Classes
-- | Arrows with a clock.
class Arrow >~ => ArrowClock >~ where { type family Time >~; }
arrTime :: ArrowClock >~ => a >~ Time >~
-- | Arrows which support running IO computations.
class Arrow >~ => ArrowIO >~
arrIO :: ArrowIO >~ => IO b >~ b
-- | Arrows with support for random number generation.
class Arrow >~ => ArrowRandom >~
arrRand :: (ArrowRandom >~, Random b) => a >~ b
arrRandR :: (ArrowRandom >~, Random b) => (b, b) >~ b
instance ArrowRandom (Kleisli IO)
instance MonadIO m => ArrowIO (Kleisli m)
instance ArrowClock (Kleisli IO)
-- | Types used in the netwire library.
module Control.Wire.Types
-- | Signal networks.
data Wire e >~ a b
WGen :: !a >~ (Either e b, Wire e >~ a b) -> Wire e >~ a b
WPure :: !a -> (Either e b, Wire e >~ a b) -> Wire e >~ a b
-- | Create a wire from the given stateless transformation computation.
mkFix :: Arrow >~ => (a >~ Either e b) -> Wire e >~ a b
-- | Create a wire from the given transformation computation.
mkGen :: (a >~ (Either e b, Wire e >~ a b)) -> Wire e >~ a b
-- | Create a pure wire from the given transformation function.
mkPure :: (a -> (Either e b, Wire e >~ a b)) -> Wire e >~ a b
-- | Create a pure wire from the given transformation function.
mkPureFix :: (a -> Either e b) -> Wire e >~ a b
-- | Convert the given wire to a generic arrow computation.
toGen :: Arrow >~ => Wire e >~ a b -> (a >~ (Either e b, Wire e >~ a b))
instance ArrowChoice (>~) => Category (Wire e (>~))
instance (ArrowChoice (>~), Monoid e) => ArrowZero (Wire e (>~))
instance (ArrowChoice (>~), ArrowWriter w (>~)) => ArrowWriter w (Wire e (>~))
instance ArrowChoice (>~) => ArrowTransformer (Wire e) (>~)
instance (ArrowChoice (>~), ArrowState s (>~)) => ArrowState s (Wire e (>~))
instance (ArrowChoice (>~), ArrowReader r (>~)) => ArrowReader r (Wire e (>~))
instance (ArrowChoice (>~), Monoid e) => ArrowPlus (Wire e (>~))
instance (ArrowChoice (>~), ArrowLoop (>~)) => ArrowLoop (Wire e (>~))
instance (Applicative f, ArrowChoice (>~), ArrowIO (>~)) => ArrowIO (Wire (f SomeException) (>~))
instance ArrowChoice (>~) => ArrowError e (Wire e (>~))
instance (ArrowChoice (>~), ArrowLoop (>~)) => ArrowCircuit (Wire e (>~))
instance ArrowChoice (>~) => ArrowChoice (Wire e (>~))
instance ArrowChoice (>~) => Arrow (Wire e (>~))
-- | Wire sessions, i.e. running and/or testing wires.
module Control.Wire.Session
-- | Performs an instant of the given wire.
stepWire :: Arrow >~ => Wire e >~ a b -> (a >~ (Either e b, Wire e >~ a b))
-- | Test a wire. This function runs the given wire continuously printing
-- its output on a single line.
testWire :: (ArrowApply >~, ArrowIO >~, Show e) => Int -> (() >~ a) -> (Wire e >~ a String >~ ())
-- | Various wires for queuing.
module Control.Wire.Prefab.Queue
-- | Queues incoming signals and acts as a dam outputting incoming signals
-- in a FIFO fashion (one-way pipe). Note: Incorrect usage can lead to
-- congestion.
--
--
-- - Depends: current instant.
-- - Inhibits: when the queue is empty.
--
fifo :: Monoid e => Wire e >~ [a] a
-- | Queues incoming signals and acts as a dam outputting incoming signals
-- in a LIFO fashion (stack). Note: Incorrect usage can lead to
-- congestion.
--
--
-- - Depends: current instant.
-- - Inhibits: when the queue is empty.
--
lifo :: Monoid e => Wire e >~ [a] a
-- | Basic wires.
module Control.Wire.Prefab.Simple
-- | The constant wire. Outputs the given value all the time.
constant :: b -> Wire e >~ a b
-- | The identity wire. Outputs its input signal unchanged.
--
--
-- - Depends: Current instant.
--
identity :: Wire e >~ a a
-- | Force the input signal to weak head normal form, before outputting it.
-- Applies seq to the input signal.
--
--
-- - Depends: Current instant.
--
force :: Wire e >~ b b
-- | Force the input signal to normal form, before outputting it. Applies
-- deepseq to the input signal.
--
--
-- - Depends: Current instant.
--
forceNF :: NFData b => Wire e >~ b b
-- | Inject the given Either value as a signal. Left means
-- inhibition.
--
--
-- - Depends: Current instant.
-- - Inhibits: When input is Left.
--
inject :: Wire e >~ (Either e b) b
-- | Inject the given Maybe value as a signal. Nothing means
-- inhibition.
--
--
-- - Depends: Current instant.
-- - Inhibits: When input is Nothing.
--
injectEvent :: Monoid e => Wire e >~ (Maybe b) b
-- | Wires for signal accumulation.
module Control.Wire.Prefab.Accum
-- | General accumulator. Outputs the argument value at the first instant,
-- then applies the input function repeatedly for subsequent instants.
-- This acts like the iterate function for lists.
--
--
-- - Depends: current instant.
--
accum :: a -> Wire e >~ (a -> a) a
-- | Count upwards from the given starting value.
countFrom :: Enum b => b -> Wire e >~ a b
-- | Count from the given starting value, repeatedly adding the input
-- signal to it.
--
--
-- - Depends: current instant.
--
countStep :: Num a => a -> Wire e >~ a a
-- | Apply the given function at the first instant. Then act as the
-- identity wire forever.
--
--
-- - Depends: Current instant.
--
atFirst :: (b -> b) -> Wire e >~ b b
-- | Wires for splitting and terminating computations.
module Control.Wire.Prefab.Split
-- | Takes the input list and forks the wire for each value. Also forks a
-- single inhibiting wire. Warning: Incorrect usage will cause space
-- leaks! Use with care!
--
--
-- - Depends: Current instant
-- - Inhibits: Always in one thread, never in all others.
-- - Threads: Length of input list + 1.
--
fork :: (ArrowChoice >~, ArrowPlus >~, Monoid e) => Wire e >~ [b] b
-- | Terminates the current wire with no output.
--
--
quit :: ArrowZero >~ => Wire e >~ a b
-- | Terminates the current wire thread with the given input value as the
-- last output.
--
--
-- - Depends: Current instant.
-- - Threads: 1, then none.
--
quitWith :: ArrowZero >~ => Wire e >~ b b
-- | Wire transformers for handling inhibited signals.
module Control.Wire.Trans.Exhibit
-- | Produces Just, whenever the argument wire produces, otherwise
-- Nothing.
--
--
-- - Depends: like argument wire.
--
event :: Arrow >~ => Wire e >~ a b -> Wire e >~ a (Maybe b)
-- | Produces Right, whenever the argument wire produces, otherwise
-- Left with the inhibition value.
--
--
-- - Depends: like argument wire.
--
exhibit :: Arrow >~ => Wire e >~ a b -> Wire e >~ a (Either e b)
-- | Simple wire transformers.
module Control.Wire.Trans.Simple
-- | Apply the given function to the input, until the argument wire starts
-- producing.
--
--
-- - Depends: Like argument wire. * Inhibits: Like argument wire.
--
(--<) :: Arrow >~ => Wire e >~ a b -> (a -> a) -> Wire e >~ a b
-- | Apply the given function to the input, until the argument wire starts
-- producing.
--
--
-- - Depends: Like argument wire. * Inhibits: Like argument wire.
--
(>--) :: Arrow >~ => (a -> a) -> Wire e >~ a b -> Wire e >~ a b
-- | Wires for calculus over time.
module Control.Wire.Prefab.Calculus
-- | Integrate over time.
--
--
-- - Depends: Current instant.
--
integral :: (ArrowClock >~, Num t, (Scalar v) ~ t, (Time >~) ~ t, VectorSpace v) => v -> Wire e >~ v v
-- | Calculates the derivative of the input signal over time.
--
--
-- - Depends: Current instant.
--
derivative :: (ArrowClock >~, Fractional t, (Scalar v) ~ t, (Time >~) ~ t, VectorSpace v) => Wire e >~ v v
-- | Various clocks.
module Control.Wire.Prefab.Clock
-- | Time deltas starting from the first instant.
dtime :: (ArrowClock >~, (Time >~) ~ t, Num t) => Wire e >~ a t
-- | Time deltas starting from the given instant.
dtimeFrom :: (ArrowClock >~, (Time >~) ~ t, Num t) => t -> Wire e >~ a t
-- | Current time with origin 0 at the first instant.
time :: (ArrowClock >~, (Time >~) ~ t, Num t) => Wire e >~ a t
-- | Current time with the given origin at the first instant.
timeFrom :: (ArrowClock >~, (Time >~) ~ t, Num t) => t -> Wire e >~ a t
-- | Current time with the given offset.
timeOffset :: (ArrowClock >~, (Time >~) ~ t, Num t) => t -> Wire e >~ a t
-- | Various signal analysis tools
module Control.Wire.Prefab.Analyze
-- | Calculate the average of the signal over the given number of last
-- samples. If you need an average over all samples ever produced,
-- consider using avgAll instead.
--
--
-- - Complexity: O(n) space, O(1) time wrt number of samples.
-- - Depends: current instant.
--
avg :: (Arrow >~, Fractional v, Unbox v) => Int -> Wire e >~ v v
-- | Calculate the average of the signal over all samples.
--
-- Please note that somewhat surprisingly this wire runs in constant
-- space and is generally faster than avg, but most applications
-- will benefit from averages over only the last few samples.
--
--
-- - Depends: current instant.
--
avgAll :: (Arrow >~, Fractional v) => Wire e >~ v v
-- | Calculate the average number of frames per virtual second for the last
-- given number of frames.
--
-- Please note that this wire uses the clock from the ArrowClock
-- instance for the underlying arrow. If this clock doesn't represent
-- real time, then the output of this wire won't either.
avgFps :: (ArrowChoice >~, ArrowClock >~, Fractional t, (Time >~) ~ t, Unbox t) => Int -> Wire e >~ a t
-- | Outputs the high peak of the input signal.
--
--
-- - Depends: Current instant.
--
highPeak :: Ord b => Wire e >~ b b
-- | Outputs the low peak of the input signal.
--
--
-- - Depends: Current instant.
--
lowPeak :: Ord b => Wire e >~ b b
-- | Outputs the high peak of the input signal with respect to the given
-- comparison function.
--
--
-- - Depends: Current instant.
--
peakBy :: (b -> b -> Ordering) -> Wire e >~ b b
-- | Collects all distinct inputs ever received.
--
--
-- - Complexity: O(n) space, O(log n) time wrt collected inputs so
-- far.
-- - Depends: current instant.
--
collect :: Ord b => Wire e >~ b (Set b)
-- | Outputs the last input value on every change of the input signal. Acts
-- like the identity wire at the first instant.
--
--
-- - Depends: current instant.
-- - Inhibits: on no change after the first instant.
--
diff :: (Eq b, Monoid e) => Wire e >~ b b
-- | Reports the first time the given input was seen.
--
--
-- - Complexity: O(n) space, O(log n) time wrt collected inputs so
-- far.
-- - Depends: Current instant.
--
firstSeen :: (ArrowChoice >~, ArrowClock >~, Monoid e, Ord a, (Time >~) ~ t) => Wire e >~ a t
-- | Reports the last time the given input was seen. Inhibits when seeing a
-- signal for the first time.
--
--
-- - Complexity: O(n) space, O(log n) time wrt collected inputs so
-- far.
-- - Depends: Current instant.
-- - Inhibits: On first sight of a signal.
--
lastSeen :: (ArrowClock >~, Monoid e, Ord a, (Time >~) ~ t) => Wire e >~ a t
-- | Wires for generating and manipulating events.
module Control.Wire.Prefab.Event
-- | Produces once after the input time delta has passed.
--
--
-- - Depends: Current instant.
-- - Inhibits: Always except at the target instant.
--
after :: (ArrowClock >~, Monoid e, Num t, Ord t, (Time >~) ~ t) => Wire e >~ t ()
-- | Produces once as soon as the current time is later than or equal to
-- the current time and never again.
--
--
-- - Depends: Current instant.
-- - Inhibits: Always except at the target instant.
--
at :: (ArrowClock >~, Monoid e, Ord t, (Time >~) ~ t) => Wire e >~ t ()
-- | Delays each incoming event (left signal) by the given time delta
-- (right signal). The time delta at the instant the event happened is
-- significant.
--
--
-- - Depends: Current instant.
-- - Inhibits: When no delayed event happened.
--
delayEvents :: (ArrowClock >~, Monoid e, Num t, Ord t, (Time >~) ~ t) => Wire e >~ ([b], t) b
-- | Delays each incoming event (left signal) by the given time delta
-- (middle signal). The time delta at the instant the event happened is
-- significant. The right signal gives a maximum number of events queued.
-- When exceeded, new events are dropped, until there is enough room.
--
--
-- - Depends: Current instant.
-- - Inhibits: When no delayed event happened.
--
delayEventsSafe :: (ArrowClock >~, Monoid e, Num t, Ord t, (Time >~) ~ t) => Wire e >~ (([b], t), Int) b
-- | Periodically produces an event. The period is given by the input time
-- delta and can change over time. The current time delta with respect to
-- the last production is significant. Does not produce at the first
-- instant, unless the first delta is nonpositive.
--
--
-- - Depends: Current instant.
-- - Inhibits: Always except at the periodic ticks.
--
periodically :: (ArrowClock >~, Monoid e, Num t, Ord t, (Time >~) ~ t) => Wire e >~ t ()
-- | Never produces. Always inhibits with the current input signal.
--
--
-- - Depends: Current instant.
-- - Inhibits: Always.
--
inhibit :: Wire e >~ e b
-- | Never produces. Equivalent to zeroArrow.
--
--
never :: Monoid e => Wire e >~ a b
-- | Inhibits as long as the input signal is False. Once it switches
-- to True, it produces forever.
--
--
-- - Depends: Current instant.
-- - Inhibits: As long as input signal is False, then never
-- again.
--
asSoonAs :: Monoid e => Wire e >~ Bool ()
-- | Produces once whenever the input signal switches from False to
-- True.
--
--
-- - Depends: Current instant.
-- - Inhibits: Always except at the above mentioned instants.
--
edge :: Monoid e => Wire e >~ Bool ()
-- | Produces, whenever the current input signal is True.
--
--
-- - Depends: Current instant.
-- - Inhibits: When input is False.
--
require :: Monoid e => Wire e >~ Bool ()
-- | Produces, whenever the current input signal is False.
--
--
-- - Depends: Current instant.
-- - Inhibits: When input is True.
--
forbid :: Monoid e => Wire e >~ Bool ()
-- | Produce as long as the input signal is True. Once it switches
-- to False, never produce again. Corresponds to takeWhile
-- for lists.
--
--
-- - Depends: Current instant.
-- - Inhibits: As soon as input becomes False.
--
while :: Monoid e => Wire e >~ Bool ()
-- | Inhibit at the first instant. Then produce forever.
--
--
-- - Inhibits: At the first instant.
--
notYet :: Monoid e => Wire e >~ b b
-- | Acts like the identity function once and never again.
--
--
-- - Inhibits: After the first instant.
--
once :: Monoid e => Wire e >~ b b
-- | Wires for generating random noise.
module Control.Wire.Prefab.Random
-- | Generate random noise.
noise :: (ArrowRandom >~, Random b) => Wire e >~ a b
-- | Generate random noise in a certain range given by the input signal.
--
--
-- - Depends: Current instant.
--
noiseR :: (ArrowRandom >~, Random b) => Wire e >~ (b, b) b
-- | Generate random noise in range 0 <= x < 1.
noiseF :: ArrowRandom >~ => Wire e >~ a Double
-- | Generate random noise in range -1 <= x < 1.
noiseF1 :: ArrowRandom >~ => Wire e >~ a Double
-- | Generate a random boolean, where the input signal is the probability
-- to be True.
--
--
-- - Depends: Current instant.
--
wackelkontakt :: ArrowRandom >~ => Wire e >~ Double Bool
-- | Signal sampling wires.
module Control.Wire.Prefab.Sample
-- | Sample the right signal at discrete intervals given by the left input
-- signal.
--
--
-- - Depends: Current instant (left), last sampling instant
-- (right).
--
discrete :: (ArrowClock >~, Num t, Ord t, (Time >~) ~ t) => Wire e >~ (t, b) b
-- | Keep the signal in the first instant forever.
--
--
-- - Depends: First instant.
--
keep :: Wire e >~ b b
-- | Convenience module importing all the prefab wires.
module Control.Wire.Prefab
-- | Wire transformers for combining wires.
module Control.Wire.Trans.Combine
-- | Make the given wire context-sensitive. The right signal is a context
-- and the wire will evolve individually for each context.
--
--
-- - Depends: Like context wire (left), current instant (right). *
-- Inhibits: Like context wire.
--
context :: (ArrowApply >~, ArrowChoice >~, Ord k) => Wire e >~ a b -> Wire e >~ (a, k) b
-- | Same as context, but with a time limit. The third signal
-- specifies a maximum age. Contexts not used for longer than the maximum
-- age are forgotten.
--
--
-- - Depends: Like context wire (left), current instant (right). *
-- Inhibits: Like context wire.
--
contextLimit :: (ArrowApply >~, ArrowClock >~, Num t, Ord k, Ord t, (Time >~) ~ t) => Wire e >~ a b -> Wire e >~ ((a, k), t) b
-- | Distribute the input signal over the given wires, evolving each of
-- them individually. Collects produced outputs.
--
-- Note: This wire transformer discards all inhibited signals.
--
--
-- - Depends: as strict as the strictest subwire.
--
distribute :: ArrowApply >~ => [Wire e >~ a b] -> Wire e >~ a [b]
-- | Wire transformers for sampling wires.
module Control.Wire.Trans.Sample
-- | Keeps the latest produced value.
--
--
-- - Depends: Like argument wire. * Inhibits: Until first
-- production.
--
hold :: Arrow >~ => Wire e >~ a b -> Wire e >~ a b
-- | Keeps the latest produced value. Produces the argument value until the
-- argument wire starts producing.
--
--
-- - Depends: Like argument wire.
--
holdWith :: Arrow >~ => b -> Wire e >~ a b -> Wire e >~ a b
-- | Samples the given wire at discrete intervals. Only runs the input
-- through the wire, then the next sampling interval has elapsed.
--
--
-- - Depends: Current instant (left), like argument wire at sampling
-- intervals (right). * Inhibits: Starts inhibiting when argument wire
-- inhibits. Keeps inhibiting until next sampling interval.
--
sample :: (ArrowChoice >~, ArrowClock >~, Num t, Ord t, (Time >~) ~ t) => Wire e >~ a b -> Wire e >~ (a, t) b
-- | Waits for the argument wire to produce and then keeps the first
-- produced value forever.
--
--
-- - Depends: Like argument wire until first production. Then stops
-- depending. * Inhibits: Until the argument wire starts producing.
--
swallow :: ArrowChoice >~ => Wire e >~ a b -> Wire e >~ a b
-- | Wire transformers.
module Control.Wire.Trans
-- | Convenience module for the Netwire library.
module Control.Wire