-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Flexible wire arrows for FRP
--
-- Efficient and flexible wire arrows for functional reactive programming
-- and other forms of locally stateful programming.
@package netwire
@version 4.0.6
-- | Timed maps for efficient cleanups in the context wires.
module Control.Wire.TimedMap
-- | A timed map is a map with an additional index based on time.
data TimedMap t k a
-- | Like lookup, but with a default value, if the key is not in the
-- map.
findWithDefault :: Ord k => (a, t) -> k -> TimedMap t k a -> (a, t)
-- | Look up the given key in the timed map.
lookup :: Ord k => k -> TimedMap t k a -> Maybe (a, t)
-- | Empty timed map.
empty :: TimedMap t k a
-- | Insert into the timed map.
insert :: (Ord k, Ord t) => t -> k -> a -> TimedMap t k a -> TimedMap t k a
-- | Remove all elements older than the given time.
cleanup :: (Ord k, Ord t) => t -> TimedMap t k a -> TimedMap t k a
-- | Remove all but the given number of latest elements.
cut :: (Ord k, Ord t) => Int -> TimedMap t k a -> TimedMap t k a
-- | Deletes the given key from the timed map.
delete :: (Ord k, Ord t) => k -> TimedMap t k a -> TimedMap t k a
instance Typeable3 TimedMap
instance (Data t, Data k, Data a, Ord t, Ord k) => Data (TimedMap t k a)
instance (Show t, Show k, Show a) => Show (TimedMap t k a)
-- | This is the core module implementing the Wire type.
module Control.Wire.Wire
-- | A wire is a signal function from an input value of type a
-- that either produces an output value of type b or
-- inhibits with a value of type e. The underlying monad
-- is m.
data Wire e m a b
WGen :: (Time -> a -> m (Either e b, Wire e m a b)) -> Wire e m a b
WPure :: (Time -> a -> (Either e b, Wire e m a b)) -> Wire e m a b
-- | Time.
type Time = Double
-- | Construct a pure stateless wire from the given function.
mkFix :: (Time -> a -> Either e b) -> Wire e m a b
-- | Construct a stateless effectful wire from the given function.
mkFixM :: Monad m => (Time -> a -> m (Either e b)) -> Wire e m a b
-- | Construct an effectful wire from the given function.
mkGen :: (Time -> a -> m (Either e b, Wire e m a b)) -> Wire e m a b
-- | Construct a pure wire from the given function.
mkPure :: (Time -> a -> (Either e b, Wire e m a b)) -> Wire e m a b
-- | Construct a pure wire from the given local state transision function.
mkState :: s -> (Time -> (a, s) -> (Either e b, s)) -> Wire e m a b
-- | Construct a monadic wire from the given local state transision
-- function.
mkStateM :: Monad m => s -> (Time -> (a, s) -> m (Either e b, s)) -> Wire e m a b
-- | Variant of pure without the Monad constraint. Using
-- pure is preferable.
constant :: b -> Wire e m a b
-- | Variant of id without the Monad constraint. Using
-- id is preferable.
identity :: Wire e m a a
-- | Variant of empty without the Monad constraint. Using
-- empty is preferable.
never :: Monoid e => Wire e m a b
-- | Map the given function over the raw wire output.
mapOutput :: Monad m => (Either e b' -> Either e b) -> Wire e m a b' -> Wire e m a b
-- | Perform an instant of the given wire.
stepWire :: Monad m => Wire e m a b -> Time -> a -> m (Either e b, Wire e m a b)
-- | Perform an instant of the given pure wire.
stepWireP :: Wire e Identity a b -> Time -> a -> (Either e b, Wire e Identity a b)
instance (Monad m, VectorSpace b) => VectorSpace (Wire e m a b)
instance (Monad m, Read b) => Read (Wire e m a b)
instance Monad m => Profunctor (Wire e m)
instance (Monad m, Monoid b) => Monoid (Wire e m a b)
instance (IsString b, Monad m) => IsString (Wire e m a b)
instance (Monad m, Num b) => Num (Wire e m a b)
instance (InnerSpace b, Monad m) => InnerSpace (Wire e m a b)
instance (HasNormal b, Monad m) => HasNormal (Wire e m a b)
instance (HasCross3 b, Monad m) => HasCross3 (Wire e m a b)
instance (HasCross2 b, Monad m) => HasCross2 (Wire e m a b)
instance Monad m => Functor (Wire e m a)
instance (Fractional b, Monad m) => Fractional (Wire e m a b)
instance (Floating b, Monad m) => Floating (Wire e m a b)
instance Monad m => Category (Wire e m)
instance (Monad m, Monoid e) => ArrowZero (Wire e m)
instance (Monad m, Monoid e) => ArrowPlus (Wire e m)
instance MonadFix m => ArrowLoop (Wire e m)
instance Monad m => ArrowChoice (Wire e m)
instance Monad m => Arrow (Wire e m)
instance Monad m => Applicative (Wire e m a)
instance (Monad m, Monoid e) => Alternative (Wire e m a)
instance (AdditiveGroup (Diff b), AffineSpace b, Monad m) => AffineSpace (Wire e m a b)
instance (AdditiveGroup b, Monad m) => AdditiveGroup (Wire e m a b)
-- | Accumulation wires. These are left-scan equivalents of several sorts.
module Control.Wire.Prefab.Accum
-- | The most general accumulator. This wire corresponds to a left scan.
--
--
-- - Depends: previous instant.
--
accum :: (b -> a -> b) -> b -> Wire e m a b
-- | Like accum, but the accumulation function also receives the
-- current time delta.
--
--
-- - Depends: previous instant.
--
accumT :: (Time -> b -> a -> b) -> b -> Wire e m a b
-- | Non-delaying variant of accum.
--
--
-- - Depends: current instant.
--
accum1 :: (b -> a -> b) -> b -> Wire e m a b
-- | Non-delaying variant of accumT.
--
--
-- - Depends: current instant.
--
accumT1 :: (Time -> b -> a -> b) -> b -> Wire e m a b
-- | Apply the input function continously. Corresponds to iterate
-- for lists.
iterateW :: (b -> b) -> b -> Wire e m a b
-- | Like iterate, but the accumulation function also receives the
-- current time delta.
iterateWT :: (Time -> b -> b) -> b -> Wire e m a b
-- | Corresponds to unfoldr for lists.
--
--
-- - Depends: current instant, if the unfolding function is strict in
-- its second argument.
--
unfold :: (s -> a -> (b, s)) -> s -> Wire e m a b
-- | Like unfold, but the accumulation function also receives the
-- current time delta.
--
--
-- - Depends: current instant, if the given function is strict in its
-- third argument.
--
unfoldT :: (Time -> s -> a -> (b, s)) -> s -> Wire e m a b
-- | Counts from the given vector adding the current input for the next
-- instant.
--
--
-- - Depends: previous instant.
--
countFrom :: AdditiveGroup b => b -> Wire e m b b
-- | Enumerates from the given element.
enumFromW :: Enum b => b -> Wire e m a b
-- | Running Monoid sum.
--
--
-- - Depends: previous instant.
--
mconcatW :: Monoid b => Wire e m b b
-- | Wires acting as queues.
module Control.Wire.Prefab.Queue
-- | Incoming values are placed in a set, which is discharged element by
-- element. Lower values are served first. Duplicate values are served
-- once.
--
-- Note: Incorrect usage can lead to congestion.
--
--
-- - Complexity: O(n) space wrt bag size.
-- - Depends: current instant.
-- - Inhibits: when the bag is empty.
--
bag :: (Monoid e, Ord b) => Wire e m (Set b) b
-- | First in, first out. The input list is placed on the right end of a
-- queue at every instant, giving earlier elements a higher priority. The
-- queue is discharged item by item from the left.
--
-- Note: Incorrect usage can lead to congestion.
--
--
-- - Complexity: O(n) space wrt queue size.
-- - Depends: current instant.
-- - Inhibits: when the queue is currently empty.
--
fifo :: Monoid e => Wire e m [b] b
-- | Last in, first out. The input list is placed on a stack at every
-- instant, giving earlier elements a higher priority. The stack is
-- discharged item by item from the top.
--
-- Note: Incorrect usage can lead to congestion.
--
--
-- - Complexity: O(n) space wrt stack size.
-- - Depends: current instant.
-- - Inhibits: when the stack is currently empty.
--
lifo :: Monoid e => Wire e m [b] b
-- | Signal sampling wires.
module Control.Wire.Prefab.Sample
-- | Produce the most recent inputs in the given time window. The left
-- input signal is the sample, the right input signal is the time window.
--
--
-- - Complexity: O(n), where n the number of samples in the time
-- window.
-- - Depends: current instant.
--
--
-- Keep the input signal of the first instant forever.
--
-- Depends: first instant.
keep :: Wire e m a a
-- | Sample the left signal at discrete intervals given by the right
-- signal.
--
--
-- - Depends: instant of the last sample.
--
sample :: Wire e m (a, Time) a
-- | Produce up to the given number of most recent inputs.
--
--
-- - Complexity: O(n), where n is the given argument.
-- - Depends: current instant.
--
window :: Int -> Wire e m a (Seq a)
-- | Same as fmap toList . window.
windowList :: Monad m => Int -> Wire e m a [a]
-- | Basic wires.
module Control.Wire.Prefab.Simple
-- | Convenience function to add another signal.
--
--
-- - Depends: current instant.
--
append :: Monad m => Wire e m a b -> Wire e m a (a, b)
-- | One-instant delay.
--
--
-- - Depends: previous instant.
--
delay :: a -> Wire e m a a
-- | Convenience function to add another signal.
--
--
-- - Depends: current instant.
--
prepend :: Monad m => Wire e m a b -> Wire e m a (b, a)
-- | Acts like the identity wire, but forces evaluation of the signal to
-- WHNF.
--
--
-- - Depends: current instant.
--
force :: Wire e m a a
-- | Acts like the identity wire, but forces evaluation of the signal to
-- NF.
--
--
-- - Depends: current instant.
--
forceNF :: NFData a => Wire e m a a
-- | Time wires.
module Control.Wire.Prefab.Time
-- | Outputs the time delta to the last instant.
--
--
dtime :: Wire e m a Time
-- | Outputs the current local time passed since the first instant.
--
--
time :: Wire e m a Time
-- | Outputs the current local time passed since the first instant with the
-- given offset.
--
--
timeFrom :: Time -> Wire e m a Time
-- | Signal analysis wires.
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 wrt number of samples.
-- - Depends: current instant.
--
avg :: (Fractional a, VectorSpace v, Scalar v ~ a) => Int -> Wire e m v v
-- | Same as avg, but with a sampling interval. This can be used to
-- increase the performance, if the input is complicated.
--
--
-- - Complexity: O(n) space wrt number of samples.
-- - Depends: current instant.
--
avgInt :: (Fractional a, VectorSpace v, Scalar v ~ a) => Int -> Int -> Wire e m v v
-- | Calculate the average of the input signal over all samples. This is
-- usually not what you want. In most cases the avg wire is
-- preferable.
--
--
-- - Depends: current instant.
--
avgAll :: (Fractional a, VectorSpace v, Scalar v ~ a) => Wire e m v v
-- | Calculate the average number of instants per second for the last given
-- number of instants. In a continuous game or simulation this
-- corresponds to the average number of frames per second, hence the
-- name.
--
--
-- - Complexity: O(n) space wrt number of samples.
-- - Depends: time.
--
avgFps :: Monad m => Int -> Wire e m a Double
-- | Like avgFps, but sample in discrete intervals only. This can
-- greatly enhance the performance, when you have an inefficient clock
-- source.
--
--
-- - Complexity: O(n) space wrt number of samples.
-- - Depends: time.
--
avgFpsInt :: Monad m => Int -> Int -> Wire e m a Double
-- | High peak.
--
--
-- - Depends: current instant.
--
highPeak :: Ord b => Wire e m b b
-- | Low peak.
--
--
-- - Depends: current instant.
--
lowPeak :: Ord b => Wire e m b b
-- | Output the peak with respect to the given comparison function.
--
--
-- - Depends: current instant.
--
peakBy :: (b -> b -> Ordering) -> Wire e m b b
-- | Collect all distinct inputs ever received together with a count.
-- Elements not appearing in the map have not been observed yet.
--
--
-- - Complexity: O(n) space.
-- - Depends: current instant.
--
collect :: Ord b => Wire e m b (Map b Int)
-- | Outputs the first local time the input was seen.
--
--
-- - Complexity: O(n) space, O(log n) time wrt number of samples so
-- far.
-- - Depends: current instant, time.
--
firstSeen :: Ord a => Wire e m a Time
-- | Outputs the local time the input was previously seen.
--
--
-- - Complexity: O(n) space, O(log n) time wrt number of samples so
-- far.
-- - Depends: current instant, time.
-- - Inhibits: if this is the first time the input is seen.
--
lastSeen :: (Monoid e, Ord a) => Wire e m a Time
-- | This module provides the wires for various kinds of moving objects. In
-- particular this includes various calculus wires like integrals and
-- differentials.
module Control.Wire.Prefab.Move
-- | Integral wire. Produces position from velocity in the sense of the
-- given vector space.
--
--
-- - Depends: previous instant.
--
integral :: VectorSpace b => b -> Wire e m (b, Scalar b) b
-- | Same as integral, but with respect to time.
--
--
-- - Depends: previous instant.
--
integral_ :: (VectorSpace b, Scalar b ~ Time) => b -> Wire e m b b
-- | Variant of integral, where you can specify a post-update
-- function, which receives the previous position as well as the current
-- (in that order). This is useful for limiting the output (think of
-- robot arms that can't be moved freely).
--
--
-- - Depends: current instant if the post-update function is strict in
-- its first argument, previous instant if not.
--
integralLim :: VectorSpace b => (w -> b -> b -> b) -> b -> Wire e m ((b, w), Scalar b) b
-- | Same as integralLim, but with respect to time.
--
--
-- - Depends: previous instant.
--
integralLim_ :: (VectorSpace b, Scalar b ~ Time) => (w -> b -> b -> b) -> b -> Wire e m (b, w) b
-- | Non-delaying variant of integral.
--
--
-- - Depends: current instant.
--
integral1 :: VectorSpace b => b -> Wire e m (b, Scalar b) b
-- | Non-delaying variant of integral_.
--
--
-- - Depends: current instant.
--
integral1_ :: (Monad m, VectorSpace b, Scalar b ~ Time) => b -> Wire e m b b
-- | Non-delaying variant of integralLim.
--
--
-- - Depends: current instant.
--
integralLim1 :: VectorSpace b => (w -> b -> b -> b) -> b -> Wire e m ((b, w), Scalar b) b
-- | Non-delaying variant of integralLim_.
--
--
-- - Depends: current instant.
--
integralLim1_ :: (VectorSpace b, Scalar b ~ Time) => (w -> b -> b -> b) -> b -> Wire e m (b, w) b
-- | Derivative. Receives x and dt and calculates the
-- change rate dx/dt. Note that dt despite its name
-- does not have to be time.
--
-- The exception handler function is called when dt is zero.
-- That function's result is the wire's output for those instants. If you
-- don't want to handle exceptional cases specially, just pass
-- (^/) as the handler function.
--
--
-- - Depends: current instant.
--
derivative :: (Eq dt, Fractional dt, VectorSpace b, Scalar b ~ dt) => (b -> dt -> b) -> b -> Wire e m (b, dt) b
-- | Same as derivative, but with respect to time.
--
--
-- - Depends: current instant.
--
derivative_ :: (Monad m, VectorSpace b, Scalar b ~ Time) => (b -> Time -> b) -> b -> Wire e m b b
-- | Objects are generalized integrals. They are controlled through
-- velocity and/or acceleration and can be collision-checked as well as
-- instantly teleported.
--
-- The post-move update function receives the world state and the current
-- object state. It is applied just before the wire produces its output.
-- You can use it to perform collision-checks or to limit the velocity.
--
-- Note that teleportation doesn't change the velocity.
--
--
-- - Depends: current instant.
--
object :: (VectorSpace b, Scalar b ~ dt) => (w -> ObjectState b -> ObjectState b) -> ObjectState b -> Wire e m (ObjectDiff b, w, dt) (ObjectState b)
-- | Same as object, but with respect to time.
--
--
-- - Depends: current instant.
--
object_ :: (Monad m, VectorSpace b, Scalar b ~ Time) => (w -> ObjectState b -> ObjectState b) -> ObjectState b -> Wire e m (ObjectDiff b, w) (ObjectState b)
-- | Object state. This includes the position and velocity.
data ObjectState a
ObjectState :: a -> a -> ObjectState a
-- | Position.
objPosition :: ObjectState a -> a
-- | Velocity.
objVelocity :: ObjectState a -> a
-- | Differential for objects.
data ObjectDiff a
-- | Accelerate (units per second).
Accelerate :: a -> ObjectDiff a
-- | Teleport to the given position instantly (velocity will be unchanged).
Position :: a -> ObjectDiff a
-- | Specify velocity (units per second).
Velocity :: a -> ObjectDiff a
instance Typeable1 ObjectState
instance Typeable1 ObjectDiff
instance Data a => Data (ObjectState a)
instance Eq a => Eq (ObjectState a)
instance Ord a => Ord (ObjectState a)
instance Read a => Read (ObjectState a)
instance Show a => Show (ObjectState a)
instance Data a => Data (ObjectDiff a)
instance Eq a => Eq (ObjectDiff a)
instance Ord a => Ord (ObjectDiff a)
instance Read a => Read (ObjectDiff a)
instance Show a => Show (ObjectDiff a)
-- | Wire combinators to manage sets of wires.
module Control.Wire.Trans.Combine
-- | The argument function turns the input signal into a context. For each
-- context the given base wire evolves individually.
--
-- Note: Incorrect usage can lead to a memory leak. Consider using
-- contextLimit instead.
--
--
-- - Complexity: O(n) space, O(log n) time wrt to number of stored
-- contexts.
-- - Depends: current instant.
-- - Inhibits: when the context wire inhibits.
--
context :: (Monad m, Ord k) => (a -> k) -> Wire e m a b -> Wire e m a b
-- | Same as context, but keeps only the latest given number of
-- contexts.
contextLatest :: (Monad m, Ord k) => (a -> k) -> Int -> Wire e m a b -> Wire e m a b
-- | Same as context, but applies the given cleanup function to the
-- context map at every instant. This can be used to drop older wires.
contextLimit :: (Monad m, Ord k) => (a -> k) -> (forall w. Int -> Time -> TimedMap Time k w -> TimedMap Time k w) -> Wire e m a b -> Wire e m a b
-- | Broadcast the input signal to all of the given wires collecting their
-- results. Each of the given subwires is evolved individually.
--
--
-- - Depends: like the most dependent subwire.
-- - Inhibits: when any of the subwires inhibits.
--
multicast :: (Monad m, Traversable f) => f (Wire e m a b) -> Wire e m a (f b)
-- | Combinators for embedding wires.
module Control.Wire.Trans.Embed
-- | Performs the argument wire with the input time delta. It is stepped
-- often enough to catch up with the main wire. The individual results
-- are combined as given by the fold (second and third argument).
--
--
-- - Complexity: O(n) time wrt stepping the subwire, where n is the
-- number of times the subwire is stepped.
-- - Depends: like argument wire, if stepped.
-- - Inhibits: When the fold results in a Left.
--
embed :: Monad m => (a -> Time) -> (Either e c -> Either e b -> Either e c) -> Either e c -> Wire e m a b -> Wire e m a c
-- | Basic wire combinators.
module Control.Wire.Trans.Simple
-- | The wire ifW p x y acts like x, when the predicate
-- p is true, otherwise y.
--
--
-- - Complexity: like the predicate and the chosen wire.
-- - Depends: like the predicate and the chosen wire.
-- - Inhibits: when the predicate or the chosen wire inhibits.
--
ifW :: (Monad m, Monoid e) => Wire e m a Bool -> Wire e m a b -> Wire e m a b -> Wire e m a b
-- | Switching combinators. Notice that these combinators restart time when
-- switching.
module Control.Wire.Trans.Switch
-- | Behaves like the first wire until it inhibits. Switches to the second
-- wire as soon as the first one inhibits.
--
-- The andThen operator is right-associative with
-- precedence 1.
--
--
-- - Depends: like currently active wire.
-- - Inhibits: when switched to second wire and that one inhibits.
-- - Time: switching restarts time.
--
andThen :: Monad m => Wire e m a b -> Wire e m a b -> Wire e m a b
-- | If the first argument wire produces a wire, switch to it immediately.
-- If not, evolve the current wire. The second argument wire is the
-- initial wire.
--
--
-- - Depends: like event wire and the currently active wire.
-- - Inhibits: when the currently active wire inhibits.
-- - Time: switching restarts time.
--
switch :: Monad m => Wire e m a (Wire e m a b) -> Wire e m a b -> Wire e m a b
-- | Whenever the given wire inhibits, a new wire is constructed using the
-- given function.
--
--
-- - Depends: like currently active wire.
-- - Time: switching restarts time.
--
switchBy :: Monad m => (e' -> Wire e' m a b) -> Wire e' m a b -> Wire e m a b
-- | Infix variant of andThen.
--
-- This operator is right-associative with precedence 1.
(-->) :: Monad m => Wire e m a b -> Wire e m a b -> Wire e m a b
-- | Time-related wire combinators.
module Control.Wire.Trans.Time
-- | Maps the given function over the time deltas for the given wire.
--
--
-- - Complexity: like argument wire.
-- - Depends: like argument wire.
-- - Inhibits: like argument wire.
--
mapTime :: Monad m => (Time -> Time) -> Wire e m a b -> Wire e m a b
-- | Types used in Netwire. Most notably this module implements the
-- instances for the various reactive classes.
module Control.Wire.Types
-- | Monoid for the last occurred exception.
type LastException = Last SomeException
-- | Event wires are wires that act like identity wires, but may inhibit
-- depending on whether a certain event has occurred.
type Event e m a = Wire e m a a
-- | WireM equivalent of Event.
type EventM m a = WireM m a a
-- | WireP equivalent of Event.
type EventP a = WireP a a
-- | Monadic wires using LastException as the inhibition monoid.
type WireM = Wire LastException
-- | Pure wires using LastException as the inhibition monoid.
type WireP = WireM Identity
-- | Type-restricted identity wire. This is useful to specify the type of a
-- signal.
--
--
-- - Depends: current instant.
--
as :: Monad m => Proxy a -> Wire e m a a
-- | Utility to specify the input type of a wire. The argument is ignored.
-- For types with defaulting you might prefer inLike.
--
--
-- inAs (Proxy :: Proxy Double) highPeak
--
inAs :: Proxy a -> w a b -> w a b
-- | Utility to specify the input type of a wire. The first argument is
-- ignored. This is useful to make use of defaulting or when writing a
-- dummy value is actually shorter.
--
--
-- inLike (0 :: Double) highPeak
--
inLike :: a -> w a b -> w a b
-- | Type-restricted identity wire. This is useful to specify the type of a
-- signal. The argument is ignored.
--
--
-- - Depends: current instant.
--
like :: Monad m => a -> Wire e m a a
-- | Utility to specify the output type of a wire. The argument is ignored.
-- For types with defaulting you might prefer outLike.
--
--
-- outAs (Proxy :: Proxy Double) noiseM
--
outAs :: Proxy b -> w a b -> w a b
-- | Utility to specify the output type of a wire. The first argument is
-- ignored. This is useful to make use of defaulting or when writing a
-- dummy value is actually shorter.
--
--
-- outLike (0 :: Double) noiseM
--
outLike :: b -> w a b -> w a b
-- | Double proxy for use with inAs or outAs.
pDouble :: Proxy Double
-- | Float proxy for use with inAs or outAs.
pFloat :: Proxy Float
-- | Int proxy for use with inAs or outAs.
pInt :: Proxy Int
-- | Integer proxy for use with inAs or outAs.
pInteger :: Proxy Integer
-- | String proxy for use with inAs or outAs.
pString :: Proxy String
-- | Effectful wires.
module Control.Wire.Prefab.Effect
-- | Perform the input monadic action in a wire.
--
--
-- - Depends: current instant.
--
perform :: Monad m => Wire e m (m b) b
-- | Variant of executeWith for the LastException inhibition
-- monoid.
--
--
-- - Depends: current instant.
-- - Inhibits: when the action throws an exception.
--
execute :: MonadBaseControl IO m => Wire LastException m (m a) a
-- | Variant of executeWith_ for the LastException inhibition
-- monoid.
--
--
-- - Depends: current instant, if the given function is strict.
-- - Inhibits: when the action throws an exception.
--
execute_ :: MonadBaseControl IO m => (a -> m b) -> Wire LastException m a b
-- | Perform the input monadic action at every instant.
--
--
-- - Depends: current instant.
-- - Inhibits: when the action throws an exception.
--
executeWith :: MonadBaseControl IO m => (SomeException -> e) -> Wire e m (m a) a
-- | Perform the given monadic action at every instant.
--
--
-- - Depends: current instant, if the given function is strict.
-- - Inhibits: when the action throws an exception.
--
executeWith_ :: MonadBaseControl IO m => (SomeException -> e) -> (a -> m b) -> Wire e m a b
-- | Branch according to the unterlying MonadPlus instance. Note
-- that this wire branches at every instant.
--
--
-- - Depends: current instant.
--
branch :: MonadPlus m => Wire e m [a] a
-- | Quits the current branch using mzero.
quit :: MonadPlus m => Wire e m a b
-- | Acts like identity in the first instant, then quits the current branch
-- using mzero.
--
--
-- - Depends: first instant.
--
quitWith :: MonadPlus m => Wire e m a a
-- | Event-related wire combinators.
module Control.Wire.Trans.Event
-- | Try both wires combining their results with the given functions.
--
--
-- - Like argument wires.
-- - Inhibits: when both wires inhibit.
--
eitherE :: (Monad m, Monoid e) => (b1 -> b) -> (b2 -> b) -> (b1 -> b2 -> b) -> Wire e m a b1 -> Wire e m a b2 -> Wire e m a b
-- | Semigroup version of eitherE.
(<||>) :: (Monad m, Monoid e, Semigroup b) => Wire e m a b -> Wire e m a b -> Wire e m a b
-- | Hold the latest event. Produces the last produced value starting with
-- the given one.
--
--
-- - Depends: like argument wire.
--
hold :: Monad m => b -> Wire e m a b -> Wire e m a b
-- | Hold the event. Once the argument wire produces the produced value is
-- held until the argument wire produces again.
--
--
-- - Depends: like argument wire.
-- - Inhibits: until the argument wire produces for the first
-- time.
--
hold_ :: Monad m => Wire e m a b -> Wire e m a b
-- | Hold the event for the given amount of time. When the argument wire
-- produces, the produced value is kept for the given amount of time. If
-- the wire produces again while another value is kept, the new value
-- takes precedence.
--
--
-- - Depends: like argument wire.
-- - Inhibits: as described.
--
holdFor :: Monad m => Time -> Wire e m a b -> Wire e m a b
-- | Hold the event for the given number of instances. When the argument
-- wire produces, the produced value is kept for the given number of
-- instances. If the wire produces again while another value is kept, the
-- new value takes precedence.
--
--
-- - Depends: like argument wire.
-- - Inhibits: as described.
--
holdForI :: Monad m => Int -> Wire e m a b -> Wire e m a b
-- | If the argument wire inhibits, inhibit with the given exception
-- instead.
--
--
-- - Depends: like argument wire.
-- - Inhibits: like argument wire.
--
() :: Monad m => Wire e m a b -> e -> Wire e m a b
-- | Prevent a wire from inhibiting. Instead produce a signal wrapped in
-- Maybe.
--
-- Note: You probably shouldn't use this function.
--
--
-- - Depends: like argument wire.
--
event :: Monad m => Wire e m a b -> Wire e m a (Maybe b)
-- | Prevent a wire from inhibiting. Instead produce the inhibition value.
--
-- Note: You probably shouldn't use this function.
--
--
-- - Depends: like argument wire.
--
exhibit :: Monad m => Wire e m a b -> Wire e m a (Either e b)
-- | Prevent a wire from inhibiting. Instead produce False, if the
-- wire inhibited.
--
-- Note: You probably shouldn't use this function.
--
--
-- - Depends: like argument wire.
--
gotEvent :: Monad m => Wire e m a b -> Wire e m a Bool
-- | Act like the identity wire, if the argument wire inhibits. Inhibit, if
-- the argument wire produces.
--
--
-- - Depends: like argument wire.
-- - Inhibits: when argument wire produces.
--
notE :: (Monad m, Monoid e) => Event e m a -> Event e m a
-- | Proxy module to all wire combinator modules.
module Control.Wire.Trans
-- | Wire sessions.
module Control.Wire.Session
-- | Perform an instant of the given wire as part of a wire session.
--
-- This is a convenience function. You can also construct time deltas
-- yourself entirely circumventing Session. This can be useful, if
-- there is really no need for an effectful monad.
stepSession :: MonadIO m => Wire e m a b -> Session m -> a -> m (Either e b, Wire e m a b, Session m)
-- | Like stepSession, but throws an exception instead of returning
-- an Either value.
stepSession_ :: MonadIO m => WireM m a b -> Session m -> a -> m (b, WireM m a b, Session m)
-- | Like stepSession, but for pure wires.
stepSessionP :: Monad m => Wire e Identity a b -> Session m -> a -> m (Either e b, Wire e Identity a b, Session m)
-- | Like stepSessionP, but throws an exception instead of returning
-- an Either value.
stepSessionP_ :: MonadIO m => WireP a b -> Session m -> a -> m (b, WireP a b, Session m)
-- | Runs the given wire continuously and prints its result to stderr. Runs
-- forever until an exception is raised.
--
-- The printing interval sets the instants/printing ratio. The
-- higher this value, the less often the output is printed. Examples:
-- 1000 means to print at every 1000-th instant, 1 means to print at
-- every instant.
testWire :: (MonadIO m, Show e) => Int -> Int -> m a -> Session m -> Wire e m a String -> m b
-- | Like testWire, but for pure wires.
testWireP :: (MonadIO m, Show e) => Int -> Int -> m a -> Session m -> Wire e Identity a String -> m b
-- | testPrint n int mx prints a formatted version of mx
-- to stderr, if n is zero. It returns mod (succ n)
-- int. Requires n >= 0 to work properly.
--
-- This function is used to implement the printing interval used
-- in testWire and testWireM.
testPrint :: Show e => Int -> Int -> Either e String -> IO Int
-- | A session value contains time-related information.
newtype Session m
Session :: m (Time, Session m) -> Session m
sessionUpdate :: Session m -> m (Time, Session m)
-- | Construct a generic session from the given initial session value and
-- the update function. You can use this function to implement your own
-- clock.
--
-- If you just want to use real time, you may want to use
-- clockSession.
genSession :: Monad m => a -> (a -> m (Time, a)) -> Session m
-- | Construct a session using real time. This session type uses
-- getCurrentTime. If you have a faster time source, you may want
-- to use genSession instead and construct your own clock.
clockSession :: MonadIO m => Session m
-- | Construct a simple counter session. The time delta is the given
-- argument at every instant.
counterSession :: Monad m => Time -> Session m
-- | Construct a frozen session. Same as counterSession 0.
frozenSession :: Monad m => Session m
-- | Various type classes.
module Control.Wire.Classes
-- | Monads with a random number generator.
class Monad m => MonadRandom m
getRandom :: (MonadRandom m, Random a) => m a
getRandomR :: (MonadRandom m, Random a) => (a, a) -> m a
-- | Class for injectable values. See inject.
class Injectable e f
toSignal :: Injectable e f => f a -> Either e a
instance MonadRandom IO
instance Injectable e (Either e)
instance Monoid e => Injectable e Maybe
-- | Event wires.
module Control.Wire.Prefab.Event
-- | Produce after the given number of instants.
--
--
-- - Depends: current instant when producing.
-- - Inhibits: until the given number of instants has passed.
--
afterI :: Monoid e => Int -> Event e m a
-- | Variant of periodically in number of instants instead of amount
-- of time.
--
--
-- - Depends: current instant when producing.
-- - Inhibits: between the given intervals.
--
eventsI :: Monoid e => [Int] -> Event e m a
-- | Produce for the given number of instants.
--
--
-- - Depends: current instant when producing.
-- - Inhibits: after the given number of instants has passed.
--
forI :: Monoid e => Int -> Event e m a
-- | Inhibit once.
--
--
-- - Depends: current instant after the first instant.
-- - Inhibits: in the first instant.
--
notYet :: Monoid e => Event e m a
-- | Produce once.
--
--
-- - Depends: current instant in the first instant.
-- - Inhibits: after the first instant.
--
once :: Monoid e => Event e m a
-- | Produce once periodically with the given number of instants as the
-- interval.
--
--
-- - Depends: current instant when producing.
-- - Inhibits: between the intervals.
--
periodicallyI :: Monoid e => Int -> Event e m a
-- | Produce when the signal has changed and at the first instant.
--
--
-- - Depends: current instant.
-- - Inhibits: after the first instant when the input has changed.
--
changed :: (Eq a, Monoid e) => Event e m a
-- | Inject the input signal. Please keep in mind that in application code
-- it is almost always wrong to use this wire. It should only be used to
-- interact with other frameworks/abstractions, and even then it's
-- probably just a last resort.
--
-- When you want to write your own wires, consider using mkPure or
-- the various variants of it.
--
--
-- - Depends: current instant.
-- - Inhibits: depending on input signal (see Injectable).
--
inject :: Injectable e f => Wire e m (f b) b
-- | Inhibit until the given predicate holds for the input signal. Then
-- produce forever.
--
--
-- - Depends: current instant, if the predicate is strict. Once true,
-- on current instant forever.
-- - Inhibits: until the predicate becomes true.
--
asSoonAs :: Monoid e => (a -> Bool) -> Event e m a
-- | Produces once whenever the given predicate switches from False
-- to True.
--
--
-- - Depends: current instant.
-- - Inhibits: when the predicate has not just switched from
-- False to True.
--
edge :: Monoid e => (a -> Bool) -> Event e m a
-- | Same as unless.
forbid :: Monoid e => (a -> Bool) -> Event e m a
-- | Same as when.
require :: Monoid e => (a -> Bool) -> Event e m a
-- | Produce when the given predicate on the input signal does not hold.
--
--
-- - Depends: current instant if the predicate is strict.
-- - Inhibits: When the predicate is true.
--
unless :: Monoid e => (a -> Bool) -> Event e m a
-- | Produce until the given predicate on the input signal holds, then
-- inhibit forever.
--
--
-- - Depends: current instant, if the predicate is strict.
-- - Inhibits: forever as soon as the predicate becomes true.
--
until :: Monoid e => (a -> Bool) -> Event e m a
-- | Produce when the given predicate on the input signal holds.
--
--
-- - Depends: current instant if the predicate is strict.
-- - Inhibits: When the predicate is false.
--
when :: Monoid e => (a -> Bool) -> Event e m a
-- | Produce while the given predicate on the input signal holds, then
-- inhibit forever.
--
--
-- - Depends: current instant, if the predicate is strict.
-- - Inhibits: forever as soon as the predicate becomes false.
--
while :: Monoid e => (a -> Bool) -> Event e m a
-- | Produce after the given amount of time.
--
--
-- - Depends: current instant when producing, time.
-- - Inhibits: until the given amount of time has passed.
--
after :: Monoid e => Time -> Event e m a
-- | Produce once periodically. The production periods are given by the
-- argument list. When it's [1,2,3] it produces after one
-- second, then after two more seconds and finally after three more
-- seconds. When the list is exhausted, it never produces again.
--
--
-- - Depends: current instant when producing, time.
-- - Inhibits: between the given intervals.
--
events :: Monoid e => [Time] -> Event e m a
-- | Produce for the given amount of time.
--
--
-- - Depends: current instant when producing, time.
-- - Inhibits: after the given amount of time has passed.
--
for :: Monoid e => Time -> Event e m a
-- | Produce once periodically with the given time interval.
--
--
-- - Depends: current instant when producing, time.
-- - Inhibits: between the intervals.
--
periodically :: Monoid e => Time -> Event e m a
-- | Inhibit with the given value.
--
--
inhibit :: e -> Wire e m a b
-- | Various noise generators.
module Control.Wire.Prefab.Noise
-- | Pure noise generator.
noise :: (Random b, RandomGen g) => g -> Wire e m a b
-- | Pure ranged noise generator.
--
--
-- - Depends: current instant.
--
noiseR :: (Random b, RandomGen g) => g -> Wire e m (b, b) b
-- | Event: Occurs randomly with the given probability.
--
--
-- - Inhibits: wackelkontaktM p inhibits with probability
-- 1 - p.
--
wackelkontakt :: (Monoid e, RandomGen g) => Double -> g -> Event e m a
-- | Noise generator.
noiseM :: (MonadRandom m, Random b) => Wire e m a b
-- | Ranged noise generator.
--
--
-- - Depends: current instant.
--
noiseRM :: (MonadRandom m, Random b) => Wire e m (b, b) b
-- | Event: Occurs randomly with the given probability.
--
--
-- - Inhibits: wackelkontaktM p inhibits with probability
-- 1 - p.
--
wackelkontaktM :: (MonadRandom m, Monoid e) => Double -> Event e m a
-- | Proxy module for the prefab wires.
module Control.Wire.Prefab
-- | Netwire is a library for functional reactive programming, that is for
-- time-varying values. It allows you to express various reactive systems
-- elegantly and concisely by using an embedded domain-specific language.
-- Examples of such systems include
--
--
-- - games,
-- - network applications with time-varying components,
-- - simulations,
-- - stateful web applications,
-- - widget-based user interfaces.
--
--
-- This library is based on an extension of the automaton arrow. The
-- usage is explained in the following tutorial.
module Control.Wire
class Profunctor (h :: * -> * -> *)
lmap :: Profunctor h => (a -> b) -> h b c -> h a c
rmap :: Profunctor h => (b -> c) -> h a b -> h a c
-- | Any type that you wish to throw or catch as an exception must be an
-- instance of the Exception class. The simplest case is a new
-- exception type directly below the root:
--
--
-- data MyException = ThisException | ThatException
-- deriving (Show, Typeable)
--
-- instance Exception MyException
--
--
-- The default method definitions in the Exception class do what
-- we need in this case. You can now throw and catch
-- ThisException and ThatException as exceptions:
--
--
-- *Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
-- Caught ThisException
--
--
-- In more complicated examples, you may wish to define a whole hierarchy
-- of exceptions:
--
--
-- ---------------------------------------------------------------------
-- -- Make the root exception type for all the exceptions in a compiler
--
-- data SomeCompilerException = forall e . Exception e => SomeCompilerException e
-- deriving Typeable
--
-- instance Show SomeCompilerException where
-- show (SomeCompilerException e) = show e
--
-- instance Exception SomeCompilerException
--
-- compilerExceptionToException :: Exception e => e -> SomeException
-- compilerExceptionToException = toException . SomeCompilerException
--
-- compilerExceptionFromException :: Exception e => SomeException -> Maybe e
-- compilerExceptionFromException x = do
-- SomeCompilerException a <- fromException x
-- cast a
--
-- ---------------------------------------------------------------------
-- -- Make a subhierarchy for exceptions in the frontend of the compiler
--
-- data SomeFrontendException = forall e . Exception e => SomeFrontendException e
-- deriving Typeable
--
-- instance Show SomeFrontendException where
-- show (SomeFrontendException e) = show e
--
-- instance Exception SomeFrontendException where
-- toException = compilerExceptionToException
-- fromException = compilerExceptionFromException
--
-- frontendExceptionToException :: Exception e => e -> SomeException
-- frontendExceptionToException = toException . SomeFrontendException
--
-- frontendExceptionFromException :: Exception e => SomeException -> Maybe e
-- frontendExceptionFromException x = do
-- SomeFrontendException a <- fromException x
-- cast a
--
-- ---------------------------------------------------------------------
-- -- Make an exception type for a particular frontend compiler exception
--
-- data MismatchedParentheses = MismatchedParentheses
-- deriving (Typeable, Show)
--
-- instance Exception MismatchedParentheses where
-- toException = frontendExceptionToException
-- fromException = frontendExceptionFromException
--
--
-- We can now catch a MismatchedParentheses exception as
-- MismatchedParentheses, SomeFrontendException or
-- SomeCompilerException, but not other types, e.g.
-- IOException:
--
--
-- *Main> throw MismatchedParentheses catch e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses catch e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses catch e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses catch e -> putStrLn ("Caught " ++ show (e :: IOException))
-- *** Exception: MismatchedParentheses
--
class (Typeable e, Show e) => Exception e
toException :: Exception e => e -> SomeException
fromException :: Exception e => SomeException -> Maybe e
-- | The SomeException type is the root of the exception type
-- hierarchy. When an exception of type e is thrown, behind the
-- scenes it is encapsulated in a SomeException.
data SomeException :: *
SomeException :: e -> SomeException