Maintainer | Ertugrul Soeylemez <es@ertes.de> |
---|---|
Safe Haskell | None |
Wire sessions.
- stepSession :: MonadIO m => Wire e m a b -> Session m -> a -> m (Either e b, Wire e m a b, Session m)
- stepSession_ :: MonadIO m => WireM m a b -> Session m -> a -> m (b, WireM m a b, Session m)
- stepSessionP :: Monad m => Wire e Identity a b -> Session m -> a -> m (Either e b, Wire e Identity a b, Session m)
- stepSessionP_ :: MonadIO m => WireP a b -> Session m -> a -> m (b, WireP a b, Session m)
- testWire :: forall a b e m. (MonadIO m, Show e) => Int -> Int -> m a -> Session m -> Wire e m a String -> m b
- testWireP :: forall a b e m. (MonadIO m, Show e) => Int -> Int -> m a -> Session m -> Wire e Identity a String -> m b
- testPrint :: Show e => Int -> Int -> Either e String -> IO Int
- newtype Session m = Session {
- sessionUpdate :: m (Time, Session m)
- genSession :: Monad m => a -> (a -> m (Time, a)) -> Session m
- clockSession :: MonadIO m => Session m
- counterSession :: Monad m => Time -> Session m
- frozenSession :: Monad m => Session m
Performing instants
:: 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.
:: 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.
:: 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.
:: 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
:: forall a b e m . (MonadIO m, Show e) | |
=> Int | Printing interval. |
-> Int |
|
-> 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.
:: forall a b e m . (MonadIO m, Show e) | |
=> Int | Printing interval. |
-> Int |
|
-> 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
A session value contains time-related information.
Session | |
|
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.
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