| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Control.Plan.Core
Description
Prefer using the main module. If you manipulate the internals of Plan
to add fake steps, bad things might happen.
Synopsis
- class Bitraversable l => Sylvan l where
- data RunState s t = RunState !(Seq (t, s, Either (Forest s) (Timeline s t))) !(Forest s) ![Context s t]
- data Progress s t
- data Tick s t = Tick (NonEmpty (Context s t)) (Progress s t)
- data Context s t = Context {}
- data Timeline s t = Timeline !(Seq (t, s, Either (Forest s) (Timeline s t))) t
- data Tick'
- data Mandatoriness
- data Steps s w = Steps !(Seq (w, s, Mandatoriness, Steps s w)) w
- data Plan s w m i o = Plan (Steps s w) (Star (Stream (Of Tick') m) i o)
- 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
- 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 :: (Semigroup w, Monoid w, Monad m) => m o -> Plan s w m i o
- plan' :: (Semigroup w, Monoid w, Monad m) => (i -> m o) -> Plan s w m i o
- kplan :: (Semigroup w, Monoid w, Monad m) => (i -> m o) -> Plan s w m i o
- planIO :: (Semigroup w, Monoid w, MonadIO m) => IO o -> Plan s w m i o
- planIO' :: (Semigroup w, Monoid w, MonadIO m) => (i -> IO o) -> Plan s w m i o
- kplanIO :: (Semigroup w, Monoid w, MonadIO m) => (i -> IO o) -> Plan s w m i o
- zipStepsi :: 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)
- completedness :: Tick s t -> Tick (Maybe (Either t (t, Maybe t)), s) t
- contextCompletedness :: (t -> Either t (t, Maybe t)) -> Context s t -> Context (Maybe (Either t (t, Maybe t)), s) t
- adapt :: Timeline (Either t (t, t), s) t -> Timeline (Maybe (Either t (t, Maybe t)), s) t
- progressCompletedness :: t -> Progress s t -> (Progress (Maybe (Either t (t, Maybe t)), s) t, Maybe (Either t (t, Maybe t)))
- unliftPlan :: Monad m => Plan s w m () o -> m o
- unliftPlan' :: Monad m => Plan s w m i o -> i -> m o
- unliftKPlan :: Monad m => Plan s w m i o -> i -> m o
- 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
- 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)
- runPlan' :: Monad m => m t -> Plan s w m i o -> i -> Stream (Of (Tick s t)) m (Timeline s t, o)
- runKPlan :: Monad m => m t -> Plan s w m i o -> i -> Stream (Of (Tick s t)) m (Timeline s t, o)
Documentation
class Bitraversable l => Sylvan l where Source #
Instances of Sylvan are Forests with nodes of type n,
interspersed with annotations of type a, and perhaps some other extra
information.
They must satisfy
bifoldMap f (\_ -> mempty) s == foldMap (foldMap f) (toForest s)
Minimal complete definition
Methods
toForest :: l n a -> Forest n Source #
Forget about the annotations and return the underlying Forest.
Instances
| Sylvan Progress Source # | |
| Sylvan Tick Source # | |
| Sylvan Timeline Source # |
|
| Sylvan Steps Source # |
|
| Sylvan (Clown (Compose [] Tree) :: * -> * -> *) Source # | |
The execution of a Plan can make progress by skipping a step, starting a
step, or finishing a step.
Constructors
| Skipped (Forest s) | Provides the substeps that were skipped. |
| Started (Forest s) | Provides the substeps that will be executed next. |
| Finished (Timeline s t) | Provides a |
Instances
| Bitraversable Progress Source # | |
Defined in Control.Plan.Core Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Progress a b -> f (Progress c d) # | |
| Bifoldable Progress Source # | |
| Bifunctor Progress Source # | |
| Sylvan Progress Source # | |
| Functor (Progress s) Source # | |
| Foldable (Progress s) Source # | |
Defined in Control.Plan.Core Methods fold :: Monoid m => Progress s m -> m # foldMap :: Monoid m => (a -> m) -> Progress s a -> m # foldr :: (a -> b -> b) -> b -> Progress s a -> b # foldr' :: (a -> b -> b) -> b -> Progress s a -> b # foldl :: (b -> a -> b) -> b -> Progress s a -> b # foldl' :: (b -> a -> b) -> b -> Progress s a -> b # foldr1 :: (a -> a -> a) -> Progress s a -> a # foldl1 :: (a -> a -> a) -> Progress s a -> a # toList :: Progress s a -> [a] # null :: Progress s a -> Bool # length :: Progress s a -> Int # elem :: Eq a => a -> Progress s a -> Bool # maximum :: Ord a => Progress s a -> a # minimum :: Ord a => Progress s a -> a # | |
| Traversable (Progress s) Source # | |
Defined in Control.Plan.Core | |
| (Eq s, Eq t) => Eq (Progress s t) Source # | |
| (Show s, Show t) => Show (Progress s t) Source # | |
Represents some kind of progress through the Steps of a Plan while the
plan executes.
The ascending list of contexts provides the current position of the execution along the hierarchy of steps.
If the plan only has a linear sequence of steps, the list will have only one
Context.
Instances
| Bitraversable Tick Source # | |
Defined in Control.Plan.Core Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Tick a b -> f (Tick c d) # | |
| Bifoldable Tick Source # | |
| Bifunctor Tick Source # | |
| Sylvan Tick Source # | |
| Functor (Tick s) Source # | |
| Foldable (Tick s) Source # | |
Defined in Control.Plan.Core Methods fold :: Monoid m => Tick s m -> m # foldMap :: Monoid m => (a -> m) -> Tick s a -> m # foldr :: (a -> b -> b) -> b -> Tick s a -> b # foldr' :: (a -> b -> b) -> b -> Tick s a -> b # foldl :: (b -> a -> b) -> b -> Tick s a -> b # foldl' :: (b -> a -> b) -> b -> Tick s a -> b # foldr1 :: (a -> a -> a) -> Tick s a -> a # foldl1 :: (a -> a -> a) -> Tick s a -> a # elem :: Eq a => a -> Tick s a -> Bool # maximum :: Ord a => Tick s a -> a # minimum :: Ord a => Tick s a -> a # | |
| Traversable (Tick s) Source # | |
| (Eq t, Eq s) => Eq (Tick s t) Source # | |
| (Show t, Show s) => Show (Tick s t) Source # | |
Represents how far we are along a sequence of sibling steps.
For the already completed steps, a Timeline of measurements is provided. extract for the Timeline returns the starting measurement of the current step.
Instances
| Bifunctor Context Source # | |
| Functor (Context s) Source # | |
| Foldable (Context s) Source # | |
Defined in Control.Plan.Core Methods fold :: Monoid m => Context s m -> m # foldMap :: Monoid m => (a -> m) -> Context s a -> m # foldr :: (a -> b -> b) -> b -> Context s a -> b # foldr' :: (a -> b -> b) -> b -> Context s a -> b # foldl :: (b -> a -> b) -> b -> Context s a -> b # foldl' :: (b -> a -> b) -> b -> Context s a -> b # foldr1 :: (a -> a -> a) -> Context s a -> a # foldl1 :: (a -> a -> a) -> Context s a -> a # toList :: Context s a -> [a] # length :: Context s a -> Int # elem :: Eq a => a -> Context s a -> Bool # maximum :: Ord a => Context s a -> a # minimum :: Ord a => Context s a -> a # | |
| Traversable (Context s) Source # | |
Defined in Control.Plan.Core | |
| (Eq t, Eq s) => Eq (Context s t) Source # | |
| (Show t, Show s) => Show (Context s t) Source # | |
A Forest of steps tags of type s interspersed with
measurements of type t.
Instances
| Bitraversable Timeline Source # | |
Defined in Control.Plan.Core Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Timeline a b -> f (Timeline c d) # | |
| Bifoldable Timeline Source # | |
| Bifunctor Timeline Source # | |
| Sylvan Timeline Source # |
|
| Functor (Timeline s) Source # | |
| Foldable (Timeline s) Source # | |
Defined in Control.Plan.Core Methods fold :: Monoid m => Timeline s m -> m # foldMap :: Monoid m => (a -> m) -> Timeline s a -> m # foldr :: (a -> b -> b) -> b -> Timeline s a -> b # foldr' :: (a -> b -> b) -> b -> Timeline s a -> b # foldl :: (b -> a -> b) -> b -> Timeline s a -> b # foldl' :: (b -> a -> b) -> b -> Timeline s a -> b # foldr1 :: (a -> a -> a) -> Timeline s a -> a # foldl1 :: (a -> a -> a) -> Timeline s a -> a # toList :: Timeline s a -> [a] # null :: Timeline s a -> Bool # length :: Timeline s a -> Int # elem :: Eq a => a -> Timeline s a -> Bool # maximum :: Ord a => Timeline s a -> a # minimum :: Ord a => Timeline s a -> a # | |
| Traversable (Timeline s) Source # | |
Defined in Control.Plan.Core | |
| Comonad (Timeline s) Source # |
|
| (Eq t, Eq s) => Eq (Timeline s t) Source # | |
| (Show t, Show s) => Show (Timeline s t) Source # | |
data Mandatoriness Source #
Instances
| Eq Mandatoriness Source # | |
Defined in Control.Plan.Core Methods (==) :: Mandatoriness -> Mandatoriness -> Bool # (/=) :: Mandatoriness -> Mandatoriness -> Bool # | |
| Ord Mandatoriness Source # | |
Defined in Control.Plan.Core Methods compare :: Mandatoriness -> Mandatoriness -> Ordering # (<) :: Mandatoriness -> Mandatoriness -> Bool # (<=) :: Mandatoriness -> Mandatoriness -> Bool # (>) :: Mandatoriness -> Mandatoriness -> Bool # (>=) :: Mandatoriness -> Mandatoriness -> Bool # max :: Mandatoriness -> Mandatoriness -> Mandatoriness # min :: Mandatoriness -> Mandatoriness -> Mandatoriness # | |
| Show Mandatoriness Source # | |
Defined in Control.Plan.Core Methods showsPrec :: Int -> Mandatoriness -> ShowS # show :: Mandatoriness -> String # showList :: [Mandatoriness] -> ShowS # | |
A Forest of steps tags of type s interspersed with monoidal
annotations of type w.
Constructors
| Steps !(Seq (w, s, Mandatoriness, Steps s w)) w |
Instances
| Bitraversable Steps Source # | |
Defined in Control.Plan.Core Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Steps a b -> f (Steps c d) # | |
| Bifoldable Steps Source # |
|
| Bifunctor Steps Source # | |
| Sylvan Steps Source # |
|
| Functor (Steps s) Source # | |
| Foldable (Steps s) Source # | |
Defined in Control.Plan.Core Methods fold :: Monoid m => Steps s m -> m # foldMap :: Monoid m => (a -> m) -> Steps s a -> m # foldr :: (a -> b -> b) -> b -> Steps s a -> b # foldr' :: (a -> b -> b) -> b -> Steps s a -> b # foldl :: (b -> a -> b) -> b -> Steps s a -> b # foldl' :: (b -> a -> b) -> b -> Steps s a -> b # foldr1 :: (a -> a -> a) -> Steps s a -> a # foldl1 :: (a -> a -> a) -> Steps s a -> a # elem :: Eq a => a -> Steps s a -> Bool # maximum :: Ord a => Steps s a -> a # minimum :: Ord a => Steps s a -> a # | |
| Traversable (Steps s) Source # | |
| (Eq w, Eq s) => Eq (Steps s w) Source # | |
| (Show w, Show s) => Show (Steps s w) Source # | |
| Semigroup w => Semigroup (Steps s w) Source # | |
| (Semigroup w, Monoid w) => Monoid (Steps s w) Source # | |
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 Plan.
Instances
| (Semigroup w, Monoid w, Monad m) => Category (Plan s w m :: * -> * -> *) Source # | |
| (Semigroup w, Monoid w, Monad m) => Arrow (Plan s w m) Source # | |
Defined in Control.Plan.Core | |
| (Semigroup w, Monoid w, Monad m) => Profunctor (Plan s w m) Source # | |
Defined in Control.Plan.Core Methods dimap :: (a -> b) -> (c -> d) -> Plan s w m b c -> Plan s w m a d # lmap :: (a -> b) -> Plan s w m b c -> Plan s w m a c # rmap :: (b -> c) -> Plan s w m a b -> Plan s w m a c # (#.) :: Coercible c b => q b c -> Plan s w m a b -> Plan s w m a c # (.#) :: Coercible b a => Plan s w m b c -> q a b -> Plan s w m a c # | |
| Monad m => Functor (Plan s w m i) Source # | |
| (Semigroup w, Monoid w, Monad m) => Applicative (Plan s w m i) Source # | |
Defined in Control.Plan.Core | |
Arguments
| :: ([(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 Applicatives an effect cannot depend on previously obtained
values.
>>>:{let example :: Plan String () IO () () example = proc () -> do i <- step "reading" (plan (readMaybe @Int <$> getLine)) -< () skippable "writing" (plan' print) -< i in putStr . drawForest . fmap (fmap show) . toForest . mandatoriness . getSteps $ example :} (Mandatory,"reading") (Skippable,"writing")
plan :: (Semigroup w, Monoid w, Monad m) => m o -> Plan s w m i o Source #
Lift a monadic action to a Plan. The input type i remains polymorphic, usually it will become ().
plan' :: (Semigroup w, Monoid w, Monad m) => (i -> m o) -> Plan s w m i o Source #
Lift a Kleisli arrow to a Plan.
kplan :: (Semigroup w, Monoid w, Monad m) => (i -> m o) -> Plan s w m i o Source #
Deprecated: Use plan' instead.
kplanIO :: (Semigroup w, Monoid w, MonadIO m) => (i -> IO o) -> Plan s w m i o Source #
Deprecated: Use planIO' instead.
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.
completedness :: Tick s t -> Tick (Maybe (Either t (t, Maybe t)), s) t Source #
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 finished, too.
This function can be used in combination with toForest and
drawForest to render the state of each step for a Tick.
contextCompletedness :: (t -> Either t (t, Maybe t)) -> Context s t -> Context (Maybe (Either t (t, Maybe t)), s) t Source #
progressCompletedness :: t -> Progress s t -> (Progress (Maybe (Either t (t, Maybe t)), s) t, Maybe (Either t (t, Maybe t))) Source #
unliftPlan :: Monad m => Plan s w m () o -> m o Source #
Forget that there is a plan, get the underlying monadic action.
unliftPlan' :: Monad m => Plan s w m i o -> i -> m o Source #
Forget that there is a plan, get the underlying Kleisli arrow.
unliftKPlan :: Monad m => Plan s w m i o -> i -> m o Source #
Deprecated: Use unliftPlan' instead.
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.
Arguments
| :: ([(t, s, Either (Forest s) r)] -> t -> r) | A function that consumes a list of step tags of type |
| -> Timeline s t | |
| -> r |
onTick :: Monad m => (tick -> m ()) -> Stream (Of tick) m r -> m r Source #
Specify a monadic callback for processing each Tick update.
Arguments
| :: 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.