Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Monad.Schedule
Description
Run scheduled computations in any (stateful) monad, using an adapter.
This module mostly contains utilities for dealing with clock inputs. To get or
set the existing timeouts, use your RunSched
adapter on one of the functions
from Data.Schedule, which this module also re-exports.
Synopsis
- type RunSched t m = forall a. (Schedule t -> (a, Schedule t)) -> m a
- runTick :: (Monad m, Monoid a) => RunSched t m -> (t -> m a) -> m a
- runTicksTo :: (Monad m, Monoid a) => RunSched t m -> (Tick -> t -> m a) -> Tick -> m a
- getInput :: Monad m => RunSched t m -> (TickDelta -> m (Either Tick i)) -> m (Either Tick i)
- mkOutput :: (Monad m, Monoid a) => RunSched t m -> (Tick -> t -> m a) -> (i -> m a) -> Either Tick i -> m a
- tickTask :: (Monad m, Monoid a) => RunSched t m -> (forall f. Applicative f => (Tick -> f (Tick, t)) -> i -> f it) -> (it -> m a) -> i -> m a
- module Data.Schedule
Documentation
type RunSched t m = forall a. (Schedule t -> (a, Schedule t)) -> m a Source #
Something that can run Schedule
state transition functions.
This could be pure (e.g. StateT
) or
impure (e.g. reference to a PrimST
).
Examples:
primState :: PrimMonad m => RunSched t (ReaderT (PrimST m (Schedule t)) m) primState sched = asks statePrimST >>= run -> lift (run sched) state :: Monad m => RunSched t (StateT (Schedule t) m) zoom _lens . state :: Monad m => RunSched t (StateT s m)
See the unit tests for more examples.
getInput :: Monad m => RunSched t m -> (TickDelta -> m (Either Tick i)) -> m (Either Tick i) Source #
mkOutput :: (Monad m, Monoid a) => RunSched t m -> (Tick -> t -> m a) -> (i -> m a) -> Either Tick i -> m a Source #
tickTask :: (Monad m, Monoid a) => RunSched t m -> (forall f. Applicative f => (Tick -> f (Tick, t)) -> i -> f it) -> (it -> m a) -> i -> m a Source #
A more general version of mkOutput
that uses a
Prism
-like optic.
Given an inner computation it -> m a
where one branch of the it
type has
a (
tuple representing individual input tasks, return an outer
computation of type Tick
, t)i -> m a
where the i
type only has a Tick
. When
the outer computation receives these Tick
inputs, it automatically
resolves the relevant tasks of type t
that are active for that Tick
, and
passes each tuple in sequence to the wrapped inner computation.
module Data.Schedule