Safe Haskell | None |
---|---|

Language | Haskell2010 |

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)
- 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])

# Waiting action

A functor implementing a syntactical "waiting" action.

#### Instances

Functor (Wait diff) Source # | |

Eq diff => Eq1 (Wait diff) Source # | |

Ord diff => MonadSchedule (Wait diff) Source # | |

(Eq diff, Eq a) => Eq (Wait diff a) Source # | |

(Show diff, Show a) => Show (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.

`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.