| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Control.Monad.Schedule.Trans
Contents
Description
This module supplies a general purpose monad transformer that adds a syntactical "delay", or "waiting" side effect.
Synopsis
- data Wait diff a = Wait {}
- compareWait :: Ord diff => Wait diff a -> Wait diff a -> Ordering
- type ScheduleT diff = FreeT (Wait diff)
- type Schedule diff = ScheduleT diff Identity
- wait :: Monad m => diff -> ScheduleT diff m ()
- runScheduleT :: Monad m => (diff -> m ()) -> ScheduleT diff m a -> m a
- runScheduleIO :: (MonadIO m, Integral n) => ScheduleT n m a -> m a
- execScheduleT :: Monad m => ScheduleT diff m a -> m (a, [diff])
- isZero :: (Eq diff, TimeDifference diff) => diff -> Bool
Waiting action
A functor implementing a syntactical "waiting" action.
Instances
| Eq diff => Eq1 (Wait diff) Source # | |
| Functor (Wait diff) Source # | |
| Ord diff => MonadSchedule (Wait diff) Source # | |
| (Show diff, Show a) => Show (Wait diff a) Source # | |
| (Eq diff, Eq a) => Eq (Wait diff a) Source # | |
| (Ord diff, TimeDifference diff, Monad m, MonadSchedule m) => MonadSchedule (ScheduleT diff m) Source # | Run each action one step until it is discovered which action(s) are pure, or yield next. If there is a pure action, it is returned, otherwise all actions are shifted to the time when the earliest action yields. |
compareWait :: Ord diff => Wait diff a -> Wait diff a -> Ordering Source #
Compare by the time difference, regardless of the value.
Note that this would not give a lawful Ord instance since we do not compare the a.
ScheduleT
type ScheduleT diff = FreeT (Wait diff) Source #
Values in ScheduleT diff m are delayed computations with side effects in m.
Delays can occur between any two side effects, with lengths specified by a diff value.
These delays don't have any semantics, it can be given to them with runScheduleT.
wait :: Monad m => diff -> ScheduleT diff m () Source #
The side effect that waits for a specified amount.
runScheduleT :: Monad m => (diff -> m ()) -> ScheduleT diff m a -> m a Source #
Supply a semantic meaning to Wait.
For every occurrence of Wait diff in the ScheduleT diff m a value,
a waiting action is executed, depending on diff.
execScheduleT :: Monad m => ScheduleT diff m a -> m (a, [diff]) Source #
Formally execute all waiting actions, returning the final value and all moments when the schedule would have waited.