-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Arrowized FRP implementation -- -- This library provides an arrowized functional reactive programming -- (FRP) implementation. From the basic idea it is similar to Yampa and -- Animas, but has a much simpler internal representation and a lot of -- new features. @package netwire @version 1.2.7 -- | The module contains the main Wire type and its type class -- instances. It also provides convenience functions for wire developers. module FRP.NetWire.Wire -- | A wire is a network of signal transformers. data Wire :: (* -> *) -> * -> * -> * WArr :: (a -> b) -> Wire m a b WGen :: (WireState m -> a -> m (Output b, Wire m a b)) -> Wire m a b -- | The state of the wire. data WireState :: (* -> *) -> * ImpureState :: Double -> MTGen -> TVar Int -> WireState m -- | Time difference for current instant. wsDTime :: WireState m -> Double -- | Random number generator. wsRndGen :: WireState m -> MTGen -- | Request counter. wsReqVar :: WireState m -> TVar Int PureState :: Double -> WireState m -- | Time difference for current instant. wsDTime :: WireState m -> Double -- | Inhibition exception with an informative message. This exception is -- the result of signal inhibition, where no further exception -- information is available. data InhibitException InhibitException :: String -> InhibitException -- | Functor for output signals. type Output = Either SomeException -- | Signal functions are wires over the identity monad. type SF = Wire Identity -- | Time. type Time = Double -- | Clean up wire state. cleanupWireState :: WireState m -> IO () -- | Construct an InhibitException wrapped in a -- SomeException. inhibitEx :: String -> SomeException -- | Initialize wire state. initWireState :: MonadIO m => IO (WireState m) -- | Create a fixed wire from the given function. This is a smart -- constructor. It creates a stateless wire. mkFix :: Monad m => (WireState m -> a -> m (Output b)) -> Wire m a b -- | Create a generic (i.e. possibly stateful) wire from the given -- function. This is a smart constructor. Please use it instead of the -- WGen constructor for creating generic wires. mkGen :: (WireState m -> a -> m (Output b, Wire m a b)) -> Wire m a b -- | Construct an InhibitException wrapped in a SomeException -- with a message indicating that a certain event did not happen. noEvent :: SomeException -- | Extract the transition function of a wire. Unless there is reason -- (like optimization) to pattern-match against the Wire -- constructors, this function is the recommended way to evolve a wire. toGen :: Monad m => Wire m a b -> WireState m -> a -> m (Output b, Wire m a b) -- | Embeds the input wire (left signal) into the network with the given -- input signal (right signal). Each time the input wire is a -- Just, the current state of the last wire is discarded and the -- new wire is evolved instead. New wires can be generated by an event -- wire and catched via FRP.NetWire.Event.event. The initial -- wire is given by the argument. -- -- Inhibits whenever the embedded wire inhibits. Same feedback behaviour -- as the embedded wire. appEvent :: Monad m => Wire m a b -> Wire m (Maybe (Wire m a b), a) b -- | Embeds the first received input wire (left signal) into the network, -- feeding it the right signal. This wire respects its left signal only -- in the first instant, after which it wraps that wire's evolution. -- -- Inhibits whenever the embedded wire inhibits. Same feedback behaviour -- as the embedded wire. appFirst :: Monad m => Wire m (Wire m a b, a) b -- | Embeds the first instant of the input wire (left signal) into the -- network, feeding it the right signal. This wire respects its left -- signal in all instances, such that the embedded wire cannot evolve. -- -- Inhibits whenever the embedded wire inhibits. Same feedback behaviour -- as the embedded wire. appFrozen :: Monad m => Wire m (Wire m a b, a) b instance Typeable InhibitException instance Read InhibitException instance Show InhibitException instance Monad m => Functor (Wire m a) instance Monad m => Category (Wire m) instance Monad m => ArrowZero (Wire m) instance Monad m => ArrowPlus (Wire m) instance MonadFix m => ArrowLoop (Wire m) instance Monad m => ArrowChoice (Wire m) instance Monad m => ArrowApply (Wire m) instance Monad m => Arrow (Wire m) instance Monad m => Applicative (Wire m a) instance Monad m => Alternative (Wire m a) instance Exception InhibitException -- | Wire sessions. module FRP.NetWire.Session -- | Reactive sessions with the given input and output types over the given -- monad. The monad must have a MonadControlIO instance to be -- usable with the stepping functions. data Session m a b Session :: TVar Bool -> IORef (WireState m) -> IORef UTCTime -> IORef (Wire m a b) -> Session m a b -- | False, if in use. sessFreeVar :: Session m a b -> TVar Bool -- | State of the last instant. sessStateRef :: Session m a b -> IORef (WireState m) -- | Time of the last instant. sessTimeRef :: Session m a b -> IORef UTCTime -- | Wire for the next instant. sessWireRef :: Session m a b -> IORef (Wire m a b) -- | Feed the given input value into the reactive system performing the -- next instant using real time. stepWire :: MonadControlIO m => a -> Session m a b -> m (Output b) -- | Feed the given input value into the reactive system performing the -- next instant using the given time delta. stepWireDelta :: MonadControlIO m => NominalDiffTime -> a -> Session m a b -> m (Output b) -- | Feed the given input value into the reactive system performing the -- next instant, which is at the given time. This function is -- thread-safe. stepWireTime :: MonadControlIO m => UTCTime -> a -> Session m a b -> m (Output b) -- | Feed the given input value into the reactive system performing the -- next instant, which is at the given time. This function is not -- thread-safe. stepWireTime' :: MonadIO m => UTCTime -> a -> Session m a b -> m (Output b) -- | Initialize a reactive session and pass it to the given continuation. withWire :: (MonadControlIO m, MonadIO sm) => Wire sm a b -> (Session sm a b -> m c) -> m c -- | Interface to testWireStr accepting all Show instances as -- the output type. testWire :: (MonadControlIO m, Show b) => Int -> m a -> Wire m a b -> m () -- | This function provides a convenient way to test wires. It wraps a -- default loop around your wire, which just displays the output on your -- stdout in a single line (it uses an ANSI escape sequence to clear the -- line). It uses real time. testWireStr :: MonadControlIO m => Int -> m a -> Wire m a String -> m () -- | Start a wire session. sessionStart :: MonadIO m => Wire m a b -> IO (Session m a b) -- | Clean up a wire session. sessionStop :: Session m a b -> IO () -- | Pure wire sessions. module FRP.NetWire.Pure -- | Perform the next instant of a pure wire over the identity monad. stepSF :: Time -> a -> SF a b -> (Output b, SF a b) -- | Perform the next instant of a pure wire. stepWirePure :: Monad m => Time -> a -> Wire m a b -> m (Output b, Wire m a b) -- | The usual FRP tools you'll want to work with. module FRP.NetWire.Tools -- | The constant wire. Please use this function instead of arr (const -- c). -- -- Never inhibits. constant :: Monad m => b -> Wire m a b -- | Identity signal transformer. Outputs its input. -- -- Never inhibits. Feedback by delay. identity :: Monad m => Wire m a a -- | Get the local time. -- -- Never inhibits. time :: Monad m => Wire m a Time -- | Get the local time, assuming it starts from the given value. -- -- Never inhibits. timeFrom :: Monad m => Time -> Wire m a Time -- | This function corresponds to the iterate function for lists. -- Begins with an initial output value. Each time an input function is -- received, it is applied to the current accumulator and the new value -- is emitted. -- -- Never inhibits. Direct feedback. accum :: Monad m => a -> Wire m (a -> a) a -- | One-instant delay. Delay the signal for an instant returning the -- argument value at the first instant. This wire is mainly useful to add -- feedback support to wires, which wouldn't support it by themselves. -- For example, the FRP.NetWire.Analyze.avg wire does not -- support feedback by itself, but the following works: -- --
-- do rec x <- delay 1 <<< avg 1000 -< x ---- -- Never inhibits. Direct feedback. delay :: Monad m => a -> Wire m a a -- | Turn a continuous signal into a discrete one. This transformer picks -- values from the right signal at intervals of the left signal. -- -- The interval length is followed in real time. If it's zero, then this -- wire acts like second id. -- -- Never inhibits. Feedback by delay. discrete :: Monad m => Wire m (Time, a) a -- | Keep the latest output. -- -- Inhibits until first signal from argument wire. Same feedback -- properties as argument wire. hold :: Monad m => Wire m a b -> Wire m a b -- | Inject the input Either signal. -- -- Inhibits on Left signals. inject :: (Exception e, Monad m) => Wire m (Either e a) a -- | Inject the input Maybe signal. -- -- Inhibits on Nothing signals. injectMaybe :: Monad m => Wire m (Maybe a) a -- | Keep the value in the first instant forever. -- -- Never inhibits. Feedback by delay. keep :: Monad m => Wire m a a -- | Inhibit, when the left signal is true. -- -- Inhibits on true left signal. No feedback. forbid :: Monad m => Wire m (Bool, a) a -- | Inhibit, when the signal is true. -- -- Inhibits on true signal. No feedback. forbid_ :: Monad m => Wire m Bool () -- | Unconditional inhibition with the given inhibition exception. -- -- Always inhibits. inhibit :: (Exception e, Monad m) => Wire m e b -- | Unconditional inhibition with default inhibition exception. -- -- Always inhibits. inhibit_ :: Monad m => Wire m a b -- | Inhibit, when the left signal is false. -- -- Inhibits on false left signal. No feedback. require :: Monad m => Wire m (Bool, a) a -- | Inhibit, when the signal is false. -- -- Inhibits on false signal. No feedback. require_ :: Monad m => Wire m Bool () -- | This function corresponds to try for exceptions, allowing you -- to observe inhibited signals. See also -- FRP.NetWire.Event.event. -- -- Never inhibits. Same feedback properties as argument wire. exhibit :: Monad m => Wire m a b -> Wire m a (Output b) -- | Effectively prevent a wire from rewiring itself. This function will -- turn any stateful wire into a stateless wire, rendering most wires -- useless. -- -- Note: This function should not be used normally. Use it only, if you -- know exactly what you're doing. -- -- Same inhibition properties as first instant of argument wire. Same -- feedback properties as first instant of argument wire. freeze :: Monad m => Wire m a b -> Wire m a b -- | Sample the given wire at specific intervals. Use this instead of -- discrete, if you want to prevent the signal from passing -- through the wire all the time. Returns the most recent result. -- -- The left signal interval is allowed to become zero, at which point the -- signal is passed through the wire at every instant. -- -- Inhibits until the first result from the argument wire. Same feedback -- properties as argument wire. sample :: Monad m => Wire m a b -> Wire m (Time, a) b -- | Wait for the first signal from the given wire and keep it forever. -- -- Inhibits until signal from argument wire. Direct feedback, if argument -- wire never inhibits, otherwise no feedback. swallow :: Monad m => Wire m a b -> Wire m a b -- | Override the output value at the first non-inhibited instant. -- -- Same inhibition properties as argument wire. Same feedback properties -- as argument wire. (-->) :: Monad m => b -> Wire m a b -> Wire m a b -- | Override the input value, until the wire starts producing. -- -- Same inhibition properties as argument wire. Same feedback properties -- as argument wire. (>--) :: Monad m => a -> Wire m a b -> Wire m a b -- | Apply a function to the wire's output at the first non-inhibited -- instant. -- -- Same inhibition properties as argument wire. Same feedback properties -- as argument wire. (-=>) :: Monad m => (b -> b) -> Wire m a b -> Wire m a b -- | Apply a function to the wire's input, until the wire starts producing. -- -- Same inhibition properties as argument wire. Same feedback properties -- as argument wire. (>=-) :: Monad m => (a -> a) -> Wire m a b -> Wire m a b -- | Apply an arrow to a list of inputs. mapA :: ArrowChoice a => a b c -> a [b] [c] -- | Duplicate a value to a tuple. dup :: a -> (a, a) -- | Floating point modulo operation. Note that fmod n 0 = 0. fmod :: Double -> Double -> Double -- | Swap the values in a tuple. swap :: (a, b) -> (b, a) -- | Switching combinators. Note that Wire also provides a -- state-preserving Control.Arrow.ArrowApply instance, which may -- be more convenient than these combinators in many cases. module FRP.NetWire.Switch -- | This is the most basic switching combinator. It is an event-based -- one-time switch. -- -- The first argument is the initial wire, which may produce a switching -- event at some point. When this event is produced, then the signal path -- switches to the wire produced by the second argument function. switch :: Monad m => Wire m a (b, Maybe c) -> (c -> Wire m a b) -> Wire m a b -- | Decoupled variant of switch. dSwitch :: Monad m => Wire m a (b, Maybe c) -> (c -> Wire m a b) -> Wire m a b -- | Combinator for recurrent switches. The wire produced by this switch -- takes switching events and switches to the wires contained in the -- events. The first argument is the initial wire. rSwitch :: Monad m => Wire m a b -> Wire m (a, Maybe (Wire m a b)) b -- | Decoupled variant of rSwitch. drSwitch :: Monad m => Wire m a b -> Wire m (a, Maybe (Wire m a b)) b -- | Broadcast signal to a collection of signal functions. If any of the -- wires inhibits, then the whole parallel network inhibits. parB :: (Applicative m, Monad m, Traversable f) => f (Wire m a b) -> Wire m a (f b) -- | Recurrent parallel broadcast switch. This combinator acts like -- parB, but takes an additional event signal, which can transform -- the set of wires. -- -- Just like parB if any of the wires inhibits, the whole network -- inhibits. rpSwitchB :: (Applicative m, Monad m, Traversable f) => f (Wire m a b) -> Wire m (a, Maybe (f (Wire m a b) -> f (Wire m a b))) (f b) -- | Decoupled variant of rpSwitchB. drpSwitchB :: (Applicative m, Monad m, Traversable f) => f (Wire m a b) -> Wire m (a, Maybe (f (Wire m a b) -> f (Wire m a b))) (f b) -- | Route signal to a collection of signal functions using the supplied -- routing function. If any of the wires inhibits, the whole network -- inhibits. par :: (Applicative m, Monad m, Traversable f) => (forall w. a -> f w -> f (b, w)) -> f (Wire m b c) -> Wire m a (f c) -- | Recurrent parallel routing switch. This combinator acts like -- par, but takes an additional event signal, which can transform -- the set of wires. This is the most powerful switch. -- -- Just like par if any of the wires inhibits, the whole network -- inhibits. rpSwitch :: (Applicative m, Monad m, Traversable f) => (forall w. a -> f w -> f (b, w)) -> f (Wire m b c) -> Wire m (a, Maybe (f (Wire m b c) -> f (Wire m b c))) (f c) -- | Decoupled variant of rpSwitch. drpSwitch :: (Applicative m, Monad m, Traversable f) => (forall w. a -> f w -> f (b, w)) -> f (Wire m b c) -> Wire m (a, Maybe (f (Wire m b c) -> f (Wire m b c))) (f c) -- | Embeds the input wire (left signal) into the network with the given -- input signal (right signal). Each time the input wire is a -- Just, the current state of the last wire is discarded and the -- new wire is evolved instead. New wires can be generated by an event -- wire and catched via FRP.NetWire.Event.event. The initial -- wire is given by the argument. -- -- Inhibits whenever the embedded wire inhibits. Same feedback behaviour -- as the embedded wire. appEvent :: Monad m => Wire m a b -> Wire m (Maybe (Wire m a b), a) b -- | Embeds the first received input wire (left signal) into the network, -- feeding it the right signal. This wire respects its left signal only -- in the first instant, after which it wraps that wire's evolution. -- -- Inhibits whenever the embedded wire inhibits. Same feedback behaviour -- as the embedded wire. appFirst :: Monad m => Wire m (Wire m a b, a) b -- | Embeds the first instant of the input wire (left signal) into the -- network, feeding it the right signal. This wire respects its left -- signal in all instances, such that the embedded wire cannot evolve. -- -- Inhibits whenever the embedded wire inhibits. Same feedback behaviour -- as the embedded wire. appFrozen :: Monad m => Wire m (Wire m a b, a) b -- | Object managers, unique identifiers and context-sensitive wires. module FRP.NetWire.Request -- | Messages to wire managers (see the manager wire). data MgrMsg k m a b -- | Do nothing. Send this, if the wire shouldn't be changed in an instant. MgrNop :: MgrMsg k m a b -- | Perform two operations in an instant. MgrMulti :: (MgrMsg k m a b) -> (MgrMsg k m a b) -> MgrMsg k m a b -- | Add the given wire with the given key. If the manager already has a -- wire with this key, it is overwritten. MgrAdd :: k -> (Wire m a b) -> MgrMsg k m a b -- | Delete the wire with the given key, if it exists. MgrDel :: k -> MgrMsg k m a b -- | Wire manager, which can be manipulated during the session. This is a -- convenient alternative to parallel switches. -- -- This wire manages a set of subwires, each indexed by a key. Through -- messages new subwires can be added and existing ones can be deleted. -- -- Inhibits, whenever one of the managed wires inhibits. Inherits -- feedback behaviour from the worst managed wire. manager :: (Monad m, Ord k) => Wire m (a, MgrMsg k m a b) (Map k b) -- | Make the given wire context-sensitive. The left input signal is a -- context and the argument wire will mutate individually for each such -- context. -- -- Inherits inhibition and feedback behaviour from the current context's -- wire. context :: (Ord ctx, Monad m) => Wire m (ctx, a) b -> Wire m (ctx, a) b -- | Specialized version of context. Use this one, if your contexts -- are Ints and you have a lot of them. -- -- Inherits inhibition and feedback behaviour from the current context's -- wire. contextInt :: Monad m => Wire m (Int, a) b -> Wire m (Int, a) b -- | Same as context, but with a time limit. The first signal -- specifies a threshold and the second signal specifies a maximum age. -- If the current number of contexts exceeds the threshold, then all -- contexts exceeding the maximum age are deleted. -- -- Inherits inhibition and feedback behaviour from the current context's -- wire. contextLimited :: (Ord ctx, Monad m) => Wire m (ctx, a) b -> Wire m (Int, Time, ctx, a) b -- | Specialized version of contextLimited. Use this one, if your -- contexts are Ints and you have a lot of them. -- -- Inherits inhibition and feedback behaviour from the current context's -- wire. contextLimitedInt :: Monad m => Wire m (Int, a) b -> Wire m (Int, Time, Int, a) b -- | Simplified variant of context. Takes a context signal only. context_ :: (Ord ctx, Monad m) => Wire m ctx b -> Wire m ctx b -- | Simplified variant of contextInt. Takes a context signal only. contextInt_ :: Monad m => Wire m Int b -> Wire m Int b -- | Simplified variant of contextLimited. Takes a context signal -- only. contextLimited_ :: (Ord ctx, Monad m) => Wire m ctx b -> Wire m (Int, Time, ctx) b -- | Simplified variant of contextLimitedInt. Takes a context signal -- only. contextLimitedInt_ :: Monad m => Wire m Int b -> Wire m (Int, Time, Int) b -- | Choose a new unique identifier at every instant. -- -- Never inhibits. Feedback by delay. identifier :: MonadIO m => Wire m a Int instance Eq k => Monoid (MgrMsg k m a b) -- | Noise generators. module FRP.NetWire.Random -- | Impure noise between 0 (inclusive) and 1 (exclusive). -- -- Never inhibits. noise :: MonadIO m => Wire m a Double -- | Impure noise between -1 (inclusive) and 1 (exclusive). -- -- Never inhibits. noise1 :: MonadIO m => Wire m a Double -- | Impure noise. -- -- Never inhibits. noiseGen :: (MonadIO m, MTRandom b) => Wire m a b -- | Impure noise between 0 (inclusive) and the input signal (exclusive). -- Note: The noise is generated by multiplying with a Double, -- hence the precision is limited. -- -- Never inhibits. Feedback by delay. noiseR :: (MonadIO m, Real a, Integral b) => Wire m a b -- | Impure random boolean. -- -- Never inhibits. wackelkontakt :: MonadIO m => Wire m a Bool -- | Pure noise. For impure wires it's recommended to use the impure noise -- generators. -- -- Never inhibits. pureNoise :: (Monad m, RandomGen g, Random b) => g -> Wire m a b -- | Pure noise in a range. For impure wires it's recommended to use the -- impure noise generators. -- -- Never inhibits. Feedback by delay. pureNoiseR :: (Monad m, RandomGen g, Random b) => g -> Wire m (b, b) b -- | Access the rest of the universe. module FRP.NetWire.IO -- | Execute the IO action in the input signal at every instant. -- -- Note: If the action throws an exception, then this wire inhibits the -- signal. -- -- Inhibits on exception. No feedback. execute :: MonadControlIO m => Wire m (m a) a -- | Lift the given monadic computation to a wire. The action is run at -- every instant. -- -- Never inhibits. Same feedback behaviour as the given computation. liftWire :: Monad m => Wire m (m a) a -- | Event system. None of these wires except event supports -- feedback, because they all can inhibit. module FRP.NetWire.Event -- | Produce a signal once after the specified delay and never again. The -- event's value will be the input signal at that point. after :: Monad m => Time -> Wire m a a -- | Produce an event according to the given list of time deltas and event -- values. The time deltas are relative to each other, hence from the -- perspective of switching in [(1, a), (2, b), (3, -- c)] produces the event a after one -- second, b after three seconds and -- c after six seconds. afterEach :: Monad m => [(Time, b)] -> Wire m a b -- | Produce a single event with the right signal whenever the left signal -- switches from False to True. edge :: Monad m => Wire m (Bool, a) a -- | Whenever the predicate in the first argument switches from -- False to True for the input signal, produce an event -- carrying the value given by applying the second argument function to -- the input signal. edgeBy :: Monad m => (a -> Bool) -> (a -> b) -> Wire m a b -- | Produce a single event carrying the value of the input signal, -- whenever the input signal switches to Just. edgeJust :: Monad m => Wire m (Maybe a) a -- | Never produce an event. This is equivalent to inhibit, but with -- a contextually more appropriate exception message. never :: Monad m => Wire m a b -- | Produce an event at the first instant and never again. once :: Monad m => Wire m a a -- | Emits a '()' signal each time the signal interval passes. This is a -- simpler variant of repeatedly. periodically :: Monad m => Wire m Time () -- | Emit the right signal event each time the left signal interval passes. repeatedly :: Monad m => Wire m (Time, a) a -- | Each time the signal interval passes emit the next element from the -- given list. repeatedlyList :: Monad m => [a] -> Wire m Time a -- | Event dam. Collects all values from the input list and emits one value -- at each instant. -- -- Note that this combinator can cause event congestion. If you feed -- values faster than it can produce, it will leak memory. dam :: Monad m => Wire m [a] a -- | Delay events by the time interval in the left signal. -- -- Note that this event transformer has to keep all delayed events in -- memory, which can cause event congestion. If events are fed in faster -- than they can be produced (for example when the framerate starts to -- drop), it will leak memory. Use delayEventSafe to prevent -- this. delayEvents :: Monad m => Wire m (Time, Maybe a) a -- | Delay events by the time interval in the left signal. The event queue -- is limited to the maximum number of events given by middle signal. If -- the current queue grows to this size, then temporarily no further -- events are queued. -- -- As suggested by the type, this maximum can change over time. However, -- if it's decreased below the number of currently queued events, the -- events are not deleted. delayEventsSafe :: Monad m => Wire m (Time, Int, Maybe a) a -- | Drop the given number of events, before passing events through. dropEvents :: Monad m => Int -> Wire m a a -- | Timed event gate for the right signal, which begins closed and opens -- after the time interval in the left signal has passed. dropFor :: Monad m => Wire m (Time, a) a -- | Suppress the first event occurence. notYet :: Monad m => Wire m a a -- | Pass only the first given number of events. Then suppress events -- forever. takeEvents :: Monad m => Int -> Wire m a a -- | Timed event gate for the right signal, which starts open and slams -- shut after the left signal time interval passed. takeFor :: Monad m => Wire m (Time, a) a -- | Variant of exhibit, which produces a Maybe instead of an -- Either. -- -- Never inhibits. Same feedback properties as argument wire. event :: Monad m => Wire m a b -> Wire m a (Maybe b) -- | Calculus functions. module FRP.NetWire.Calculus -- | Differentiate over time. -- -- Inhibits at first instant. derivative :: (Monad m, NFData v, VectorSpace v, (Scalar v) ~ Double) => Wire m v v -- | Differentiate over time. The argument is the value before the first -- instant. -- -- Never inhibits. Feedback by delay. derivativeFrom :: (Monad m, NFData v, VectorSpace v, (Scalar v) ~ Double) => v -> Wire m v v -- | Integrate over time. The argument is the integration constant. -- -- Never inhibits. Feedback by delay. integral :: (Monad m, NFData v, VectorSpace v, (Scalar v) ~ Double) => v -> Wire m v v -- | Signal analysis. module FRP.NetWire.Analyze -- | Emits an event, whenever the input signal changes. The event contains -- the last input value and the time elapsed since the last change. -- -- Inhibits on no change. diff :: (Eq a, Monad m) => Wire m a (a, Time) -- | Calculate the average of the signal over the given number of last -- samples. This wire has O(n) space complexity and O(1) time complexity. -- -- If you need an average over all samples ever produced, consider using -- avgAll instead. -- -- Never inhibits. Feedback by delay. avg :: (Fractional v, Monad m, NFData v, Unbox v) => Int -> Wire m 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. -- -- Never inhibits. Feedback by delay. avgAll :: (Fractional v, Monad m, NFData v) => Wire m 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, which you give the network -- using the stepping functions in FRP.NetWire.Session. If this -- clock doesn't represent real time, then the output of this wire won't -- either. -- -- Never inhibits. avgFps :: Monad m => Int -> Wire m a Double -- | Collects all the inputs ever received. This wire uses O(n) memory and -- runs in O(log n) time, where n is the number of inputs collected so -- far. -- -- Never inhibits. Feedback by delay. collect :: (Ord a, Monad m) => Wire m a (Set a) -- | Returns the time delta between now and when the input signal was last -- seen. This wire uses O(n) memory and runs in O(log n) time, where n is -- the number of inputs collected so far. -- -- Inhibits, when a signal is seen for the first time. lastSeen :: (Ord a, Monad m) => Wire m a Time -- | Return the high peak. -- -- Never inhibits. Feedback by delay. highPeak :: (Monad m, NFData a, Ord a) => Wire m a a -- | Return the low peak. -- -- Never inhibits. Feedback by delay. lowPeak :: (Monad m, NFData a, Ord a) => Wire m a a -- | Return the high peak with the given comparison function. -- -- Never inhibits. Feedback by delay. peakBy :: (Monad m, NFData a) => (a -> a -> Ordering) -> Wire m a a -- | Arrowized FRP implementation for networking applications. The aim of -- this library is to provide a convenient FRP implementation, which -- should enable you to write entirely pure network sessions. module FRP.NetWire -- | A wire is a network of signal transformers. data Wire :: (* -> *) -> * -> * -> * -- | Functor for output signals. type Output = Either SomeException -- | Time. type Time = Double -- | The state of the wire. data WireState :: (* -> *) -> * ImpureState :: Double -> MTGen -> TVar Int -> WireState m -- | Time difference for current instant. wsDTime :: WireState m -> Double -- | Random number generator. wsRndGen :: WireState m -> MTGen -- | Request counter. wsReqVar :: WireState m -> TVar Int PureState :: Double -> WireState m -- | Time difference for current instant. wsDTime :: WireState m -> Double -- | Create a generic (i.e. possibly stateful) wire from the given -- function. This is a smart constructor. Please use it instead of the -- WGen constructor for creating generic wires. mkGen :: (WireState m -> a -> m (Output b, Wire m a b)) -> Wire m a b -- | Extract the transition function of a wire. Unless there is reason -- (like optimization) to pattern-match against the Wire -- constructors, this function is the recommended way to evolve a wire. toGen :: Monad m => Wire m a b -> WireState m -> a -> m (Output b, Wire m a b) -- | Reactive sessions with the given input and output types over the given -- monad. The monad must have a MonadControlIO instance to be -- usable with the stepping functions. data Session m a b -- | Feed the given input value into the reactive system performing the -- next instant using real time. stepWire :: MonadControlIO m => a -> Session m a b -> m (Output b) -- | Feed the given input value into the reactive system performing the -- next instant using the given time delta. stepWireDelta :: MonadControlIO m => NominalDiffTime -> a -> Session m a b -> m (Output b) -- | Feed the given input value into the reactive system performing the -- next instant, which is at the given time. This function is -- thread-safe. stepWireTime :: MonadControlIO m => UTCTime -> a -> Session m a b -> m (Output b) -- | Initialize a reactive session and pass it to the given continuation. withWire :: (MonadControlIO m, MonadIO sm) => Wire sm a b -> (Session sm a b -> m c) -> m c -- | Interface to testWireStr accepting all Show instances as -- the output type. testWire :: (MonadControlIO m, Show b) => Int -> m a -> Wire m a b -> m () -- | This function provides a convenient way to test wires. It wraps a -- default loop around your wire, which just displays the output on your -- stdout in a single line (it uses an ANSI escape sequence to clear the -- line). It uses real time. testWireStr :: MonadControlIO m => Int -> m a -> Wire m a String -> m () -- | Signal functions are wires over the identity monad. type SF = Wire Identity -- | Perform the next instant of a pure wire over the identity monad. stepSF :: Time -> a -> SF a b -> (Output b, SF a b) -- | Perform the next instant of a pure wire. stepWirePure :: Monad m => Time -> a -> Wire m a b -> m (Output b, Wire m a b) -- | Inhibition exception with an informative message. This exception is -- the result of signal inhibition, where no further exception -- information is available. data InhibitException InhibitException :: String -> InhibitException -- | Construct an InhibitException wrapped in a -- SomeException. inhibitEx :: String -> SomeException -- | Construct an InhibitException wrapped in a SomeException -- with a message indicating that a certain event did not happen. noEvent :: SomeException