netwire-4.0.2: Flexible wire arrows for FRP

MaintainerErtugrul Soeylemez <es@ertes.de>
Safe HaskellNone

Control.Wire.Session

Contents

Description

Wire sessions.

Synopsis

Performing instants

stepSessionSource

Arguments

:: MonadIO m 
=> Wire e m a b

Wire to step.

-> Session m

Current session state.

-> a

Input value.

-> m (Either e b, Wire e m a b, Session m) 

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_Source

Arguments

:: MonadIO m 
=> WireM m a b

Wire to step.

-> Session m

Current session state.

-> a

Input value.

-> m (b, WireM m a b, Session m) 

Like stepSession, but throws an exception instead of returning an Either value.

stepSessionPSource

Arguments

:: Monad m 
=> Wire e Identity a b

Wire to step.

-> Session m

Current session state.

-> a

Input value.

-> m (Either e b, Wire e Identity a b, Session m) 

Like stepSession, but for pure wires.

stepSessionP_Source

Arguments

:: MonadIO m 
=> WireP a b

Wire to step.

-> Session m

Current session state.

-> a

Input value.

-> m (b, WireP a b, Session m) 

Like stepSessionP, but throws an exception instead of returning an Either value.

Testing wires

testWireSource

Arguments

:: forall a b e m . (MonadIO m, Show e) 
=> Int

Printing interval.

-> Int

threadDelay between instants.

-> m a

Input generator.

-> Session m

Initial session value.

-> Wire e m a String

Wire to test.

-> m b 

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.

testWirePSource

Arguments

:: forall a b e m . (MonadIO m, Show e) 
=> Int

Printing interval.

-> Int

threadDelay between instants.

-> m a

Input generator.

-> Session m

Initial session value.

-> Wire e Identity a String

Wire to test.

-> m b 

Like testWire, but for pure wires.

Helper functions

testPrint :: Show e => Int -> Int -> Either e String -> IO IntSource

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.

Sessions

newtype Session m Source

A session value contains time-related information.

Constructors

Session 

Fields

sessionUpdate :: m (Time, Session m)
 

Generic sessions

genSession :: Monad m => a -> (a -> m (Time, a)) -> Session mSource

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.

Specific session types

clockSession :: MonadIO m => Session mSource

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.

counterSessionSource

Arguments

:: Monad m 
=> Time

Time delta for every instant.

-> Session m 

Construct a simple counter session. The time delta is the given argument at every instant.

frozenSession :: Monad m => Session mSource

Construct a frozen session. Same as counterSession 0.