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.
Fast-forward a computation by n steps. This is essentially
equivalent to doing n
Retrieve the result of a completed step computation (or
if it is incomplete).
Run a subsidiary computation for up to n steps, translated into an equal number of steps of the parent computation.
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.
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.
Wrap a step computation to return the number of steps, in addition to the result.
Run a step computation until it finishes, and also return the number of steps it took.
Run two step computations in parallel. The first one to complete becomes the result of the computation.