Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This module provides step computations. These are computations that can be run, stopped, resumed, parallelized, and/or bounded in runtime.
- data StepComp a
- tick :: StepComp ()
- untick :: StepComp a -> StepComp a
- forward :: Int -> StepComp a -> StepComp a
- is_done :: StepComp a -> Bool
- get_result :: StepComp a -> Maybe a
- subtask :: Int -> StepComp a -> StepComp (StepComp a)
- speedup :: Int -> StepComp a -> StepComp a
- parallel :: StepComp a -> StepComp b -> StepComp (Either (a, StepComp b) (StepComp a, b))
- with_counter :: StepComp a -> StepComp (a, Int)
- run :: StepComp a -> a
- run_with_steps :: StepComp a -> (a, Int)
- run_bounded :: Int -> StepComp a -> Maybe a
- diverge :: StepComp a
- parallel_first :: StepComp a -> StepComp a -> StepComp a
- parallel_maybe :: StepComp (Maybe a) -> StepComp (Maybe b) -> StepComp (Maybe (a, b))
- parallel_list_maybe :: [StepComp (Maybe a)] -> StepComp (Maybe [a])
A monad for step computations
A step computation can be run for a specified number of steps, stopped, continued, and interleaved. Such a computation produces "ticks" at user-defined intervals, which must be consumed by the environment for the computation to continue.
Basic operations
forward :: Int -> StepComp a -> StepComp a Source #
Fast-forward a computation by n steps. This is essentially
equivalent to doing n untick
operations.
get_result :: StepComp a -> Maybe a Source #
Retrieve the result of a completed step computation (or Nothing
if it is incomplete).
subtask :: Int -> StepComp a -> StepComp (StepComp a) Source #
Run a subsidiary computation for up to n steps, translated into an equal number of steps of the parent computation.
speedup :: Int -> StepComp a -> StepComp a Source #
Run a subtask, speeding it up by a factor of n ≥ 1. Every 1 tick of the calling task corresponds to up to n ticks of the subtask.
parallel :: StepComp a -> StepComp b -> StepComp (Either (a, StepComp b) (StepComp a, b)) Source #
Run two step computations in parallel, until one branch terminates. Tick allocation is associative: each tick of the parent function translates into one tick for each subcomputation. Therefore, when running, e.g., three subcomputations in parallel, they will each receive an approximately equal number of ticks.
with_counter :: StepComp a -> StepComp (a, Int) Source #
Wrap a step computation to return the number of steps, in addition to the result.
Run functions
run_with_steps :: StepComp a -> (a, Int) Source #
Run a step computation until it finishes, and also return the number of steps it took.
Other operations
parallel_first :: StepComp a -> StepComp a -> StepComp a Source #
Run two step computations in parallel. The first one to complete becomes the result of the computation.