Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Prefer using the main module. If you manipulate the internals of Plan
to add fake steps, bad things might happen.
- data Plan s w m i o = Plan (Steps s w) (Star (Stream (Of Tick') m) i o)
- data Steps s w = Steps !(Seq (w, s, Mandatoriness, Steps s w)) w
- data Mandatoriness
- foldSteps :: ([(w, s, Mandatoriness, r)] -> w -> r) -> Steps s w -> r
- foldSteps' :: (Seq (w, s, Mandatoriness, r) -> w -> r) -> Steps s w -> r
- bimapSteps :: (s -> s') -> (w -> w') -> Plan s w m i o -> Plan s' w' m i o
- zoomSteps :: Monoid w' => ((w -> Identity w) -> w' -> Identity w') -> Plan s w m i o -> Plan s w' m i o
- hoistPlan :: Monad m => (forall x. m x -> n x) -> Plan s w m i o -> Plan s w n i o
- data Tick'
- getSteps :: Plan s w m i o -> Steps s w
- mandatoriness :: Steps s w -> Steps (Mandatoriness, s) w
- step :: (Monoid w, Monad m) => s -> Plan s w m i o -> Plan s w m i o
- skippable :: (Monoid w, Monad m) => s -> Plan s w m i o -> Plan s w m (Maybe i) ()
- foretell :: Monad m => w -> Plan s w m i ()
- plan :: (Monoid w, Monad m) => m o -> Plan s w m i o
- planIO :: (Monoid w, MonadIO m) => IO o -> Plan s w m i o
- planK :: (Monoid w, Monad m) => (i -> m o) -> Plan s w m i o
- planKIO :: (Monoid w, MonadIO m) => (i -> IO o) -> Plan s w m i o
- zipSteps' :: Forest a -> Steps r w -> Maybe (Steps (a, r) w)
- zipSteps :: Forest s' -> Plan s w m i o -> Maybe (Plan (s', s) w m i o)
- tickToForest :: Tick s t -> Forest (Maybe (Either t (t, Maybe t)), s)
- contextToForest :: Forest (Maybe (Either t (t, Maybe t)), s) -> Context s t -> Forest (Maybe (Either t (t, Maybe t)), s)
- completedToForest :: Timeline c t -> Forest (Maybe (Either t (t, Maybe t)), c)
- pendingToForest :: Forest c -> Forest (Maybe (Either t (t, Maybe t)), c)
- skippedToForest :: Forest c -> t -> Forest (Maybe (Either t (t, Maybe t)), c)
- unliftPlan :: Monad m => Plan s w m () o -> m o
- unliftPlanK :: Monad m => Plan s w m i o -> i -> m o
- data Timeline s t = Timeline !(Seq (t, s, Either (Forest s) (Timeline s t))) t
- instants :: Timeline s t -> Timeline (Either t (t, t), s) t
- foldTimeline :: ([(t, s, Either (Forest s) r)] -> t -> r) -> Timeline s t -> r
- foldTimeline' :: (Seq (t, c, Either (Forest c) r) -> t -> r) -> Timeline c t -> r
- data Context s t = Context {}
- data Tick s t = Tick (NonEmpty (Context s t)) (Progress s t)
- data Progress s t
- onTick :: Monad m => (tick -> m ()) -> Stream (Of tick) m r -> m r
- runPlan :: Monad m => m t -> Plan s w m () o -> Stream (Of (Tick s t)) m (Timeline s t, o)
- runPlanK :: Monad m => m t -> Plan s w m i o -> i -> Stream (Of (Tick s t)) m (Timeline s t, o)
- data RunState s t = RunState !(Seq (t, s, Either (Forest s) (Timeline s t))) !(Forest s) ![Context s t]
- class Bitraversable l => Lasagna l where
- inheritTree :: [a] -> Tree a -> Tree (NonEmpty a)
- foldTree' :: (a -> [b] -> b) -> Tree a -> b
Documentation
A computation that takes inputs of type i
and produces outputs of type
o
working in the underlying monad m
. The Applicative
instance cares
only about the outputs, the Arrow
instance cares about both inputs and
outputs.
Parts of the computation can be labeled as steps with tags of type s
.
Computations can have monoidal resource annotations of type w
.
The structure of steps and the monoidal annotations can be inspected before executing the computations.
A Forest
of steps tags of type s
interspersed with monoidal
annotations of type w
.
Steps !(Seq (w, s, Mandatoriness, Steps s w)) w |
Bifunctor Steps Source # | |
Bitraversable Steps Source # | |
Bifoldable Steps Source # |
|
Lasagna Steps Source # |
|
Functor (Steps s) Source # | |
Foldable (Steps s) Source # | |
Traversable (Steps s) Source # | |
(Eq s, Eq w) => Eq (Steps s w) Source # | |
(Show s, Show w) => Show (Steps s w) Source # | |
Monoid w => Monoid (Steps s w) Source # | |
data Mandatoriness Source #
Steps of Plan
s constructed in Applicative
fashion are always
Mandatory
. Only steps declared with skippable
are optional.
:: ([(w, s, Mandatoriness, r)] -> w -> r) | A function that consumes a list of step tags of type |
-> Steps s w | |
-> r |
foldSteps' :: (Seq (w, s, Mandatoriness, r) -> w -> r) -> Steps s w -> r Source #
bimapSteps :: (s -> s') -> (w -> w') -> Plan s w m i o -> Plan s' w' m i o Source #
Adapt the Step
value inside a Plan
without extracting it.
zoomSteps :: Monoid w' => ((w -> Identity w) -> w' -> Identity w') -> Plan s w m i o -> Plan s w' m i o Source #
Use a lens setter to "zoom" the monoidal annotations of a Plan
into a
wider monoidal context.
hoistPlan :: Monad m => (forall x. m x -> n x) -> Plan s w m i o -> Plan s w n i o Source #
Change the underlying monad of a Plan
.
mandatoriness :: Steps s w -> Steps (Mandatoriness, s) w Source #
Decorate each step tag with its mandatoriness. Useful in combination with toForest
.
step :: (Monoid w, Monad m) => s -> Plan s w m i o -> Plan s w m i o Source #
Declare a step by wrapping an existing plan (which may contain substeps).
skippable :: (Monoid w, Monad m) => s -> Plan s w m i o -> Plan s w m (Maybe i) () Source #
Declare an optional step by wrapping an existing arrow plan. The step will
only be executed when the input is Just
.
This function only makes sense when using the Arrow
instance of Plan
,
because for Applicative
s an effect cannot depend on previously obtained
values.
plan :: (Monoid w, Monad m) => m o -> Plan s w m i o Source #
Lift a monadic action to a Plan
. The input type remains polymorphic.
planK :: (Monoid w, Monad m) => (i -> m o) -> Plan s w m i o Source #
Lift a Kleisli arrow to a Plan
.
zipSteps :: Forest s' -> Plan s w m i o -> Maybe (Plan (s', s) w m i o) Source #
Pair each step tag s
inside a Plan
with the corresponding element of the Forest
.
If the forest doesn't have the same structure as the steps, the function
fails with Nothing
.
This function can be useful to annotate each step tag with some information,
for example the time duration of the step in a previous execution of the
plan. See Timeline
, instants
, and toForest
.
tickToForest :: Tick s t -> Forest (Maybe (Either t (t, Maybe t)), s) Source #
Transform a Tick
into a form more suitable for rendering with functions
like drawForest
.
A given step might not have been reached yet. It it has been reached, either it has been skipped at a certain time, or started at a certain time. If if has been started, maybe it has already finised, too.
contextToForest :: Forest (Maybe (Either t (t, Maybe t)), s) -> Context s t -> Forest (Maybe (Either t (t, Maybe t)), s) Source #
unliftPlan :: Monad m => Plan s w m () o -> m o Source #
Forget that there is a plan, get the underlying monadic action.
unliftPlanK :: Monad m => Plan s w m i o -> i -> m o Source #
Forget that there is a plan, get the underlying Kleisli arrow.
A Forest
of steps tags of type s
interspersed with
measurements of type t
.
Bifunctor Timeline Source # | |
Bitraversable Timeline Source # | |
Bifoldable Timeline Source # | |
Lasagna Timeline Source # |
|
Functor (Timeline s) Source # | |
Foldable (Timeline s) Source # | |
Traversable (Timeline s) Source # | |
Comonad (Timeline s) Source # |
|
(Eq s, Eq t) => Eq (Timeline s t) Source # | |
(Show s, Show t) => Show (Timeline s t) Source # | |
instants :: Timeline s t -> Timeline (Either t (t, t), s) t Source #
Decorate each step tag with either the time the step was skipped, or the
time it was started and finished. Useful in combination with toForest
.
:: ([(t, s, Either (Forest s) r)] -> t -> r) | A function that consumes a list of step tags of type |
-> Timeline s t | |
-> r |
The execution of a Plan
can make progress by skipping a step, starting a
step, or finishing a step.
onTick :: Monad m => (tick -> m ()) -> Stream (Of tick) m r -> m r Source #
Specify a monadic callback for processing each Tick
update.
:: Monad m | |
=> m t | Monadic measurement to be taken on each tick. |
-> Plan s w m () o | Plan without input. |
-> Stream (Of (Tick s t)) m (Timeline s t, o) |
Runs a plan that doesn't need input. It returns a Stream
of Tick
updates that are emitted every time the execution advances through the
Steps
.
For each Tick
update, a monadic measurement of type t
is taken. Usually
the measurement consists in getting the current time.
When the execution finishes, a Timeline
with the measurements for each
Tick
is returned, along with the result value.
Even if the plan didn't have any steps, the Timeline
will contain a
measurement taken when the computation finished.
class Bitraversable l => Lasagna l where Source #
Instances of Lasagna
are like Forest
s where each list of
sibling nodes of type n
is surrounded and interspersed with annotations of
type a
. Some instances might add extra information to each node, or
allow alternative branches.