-- 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. -- -- accum :: (b -> a -> b) -> b -> Wire e m a b -- | Like accum, but the accumulation function also receives the -- current time delta. -- -- accumT :: (Time -> b -> a -> b) -> b -> Wire e m a b -- | Non-delaying variant of accum. -- -- accum1 :: (b -> a -> b) -> b -> Wire e m a b -- | Non-delaying variant of accumT. -- -- 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. -- -- unfold :: (s -> a -> (b, s)) -> s -> Wire e m a b -- | Like unfold, but the accumulation function also receives the -- current time delta. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- -- -- 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. -- -- sample :: Wire e m (a, Time) a -- | Produce up to the given number of most recent inputs. -- -- 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. -- -- append :: Monad m => Wire e m a b -> Wire e m a (a, b) -- | One-instant delay. -- -- delay :: a -> Wire e m a a -- | Convenience function to add another signal. -- -- 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. -- -- force :: Wire e m a a -- | Acts like the identity wire, but forces evaluation of the signal to -- NF. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- avgFpsInt :: Monad m => Int -> Int -> Wire e m a Double -- | High peak. -- -- highPeak :: Ord b => Wire e m b b -- | Low peak. -- -- lowPeak :: Ord b => Wire e m b b -- | Output the peak with respect to the given comparison function. -- -- 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. -- -- collect :: Ord b => Wire e m b (Map b Int) -- | Outputs the first local time the input was seen. -- -- firstSeen :: Ord a => Wire e m a Time -- | Outputs the local time the input was previously 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. -- -- integral :: VectorSpace b => b -> Wire e m (b, Scalar b) b -- | Same as integral, but with respect to time. -- -- 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). -- -- integralLim :: VectorSpace b => (w -> b -> b -> b) -> b -> Wire e m ((b, w), Scalar b) b -- | Same as integralLim, but with respect to time. -- -- integralLim_ :: (VectorSpace b, Scalar b ~ Time) => (w -> b -> b -> b) -> b -> Wire e m (b, w) b -- | Non-delaying variant of integral. -- -- integral1 :: VectorSpace b => b -> Wire e m (b, Scalar b) b -- | Non-delaying variant of integral_. -- -- integral1_ :: (Monad m, VectorSpace b, Scalar b ~ Time) => b -> Wire e m b b -- | Non-delaying variant of integralLim. -- -- integralLim1 :: VectorSpace b => (w -> b -> b -> b) -> b -> Wire e m ((b, w), Scalar b) b -- | Non-delaying variant of integralLim_. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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). -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- perform :: Monad m => Wire e m (m b) b -- | Variant of executeWith for the LastException inhibition -- monoid. -- -- execute :: MonadBaseControl IO m => Wire LastException m (m a) a -- | Variant of executeWith_ for the LastException inhibition -- monoid. -- -- execute_ :: MonadBaseControl IO m => (a -> m b) -> Wire LastException m a b -- | Perform the input monadic action at every instant. -- -- executeWith :: MonadBaseControl IO m => (SomeException -> e) -> Wire e m (m a) a -- | Perform the given monadic action at every instant. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- () :: 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. -- -- 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. -- -- 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. -- -- 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. -- -- 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. -- -- afterI :: Monoid e => Int -> Event e m a -- | Variant of periodically in number of instants instead of amount -- of time. -- -- eventsI :: Monoid e => [Int] -> Event e m a -- | Produce for the given number of instants. -- -- forI :: Monoid e => Int -> Event e m a -- | Inhibit once. -- -- notYet :: Monoid e => Event e m a -- | Produce once. -- -- once :: Monoid e => Event e m a -- | Produce once periodically with the given number of instants as the -- interval. -- -- periodicallyI :: Monoid e => Int -> Event e m a -- | Produce when the signal has changed and at the first instant. -- -- 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. -- -- inject :: Injectable e f => Wire e m (f b) b -- | Inhibit until the given predicate holds for the input signal. Then -- produce forever. -- -- asSoonAs :: Monoid e => (a -> Bool) -> Event e m a -- | Produces once whenever the given predicate switches 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. -- -- unless :: Monoid e => (a -> Bool) -> Event e m a -- | Produce until the given predicate on the input signal holds, then -- inhibit forever. -- -- until :: Monoid e => (a -> Bool) -> Event e m a -- | Produce when the given predicate on the input signal holds. -- -- when :: Monoid e => (a -> Bool) -> Event e m a -- | Produce while the given predicate on the input signal holds, then -- inhibit forever. -- -- while :: Monoid e => (a -> Bool) -> Event e m a -- | Produce after the given amount of time. -- -- 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. -- -- events :: Monoid e => [Time] -> Event e m a -- | Produce for the given amount of time. -- -- for :: Monoid e => Time -> Event e m a -- | Produce once periodically with the given time interval. -- -- 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. -- -- noiseR :: (Random b, RandomGen g) => g -> Wire e m (b, b) b -- | Event: Occurs randomly with the given probability. -- -- 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. -- -- noiseRM :: (MonadRandom m, Random b) => Wire e m (b, b) b -- | Event: Occurs randomly with the given probability. -- -- 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 -- -- -- -- 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