Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
- data ProcessT m b c
- type ProcessA a = ProcessT (ArrowMonad a)
- class Occasional' a where
- class Occasional' a => Occasional a where
- data Event a
- noEvent :: Occasional a => a
- end :: Occasional a => a
- data ZeroEvent = ZeroEvent
- condEvent :: Bool -> Event a -> Event a
- filterEvent :: Arrow ar => (a -> Bool) -> ar (Event a) (Event a)
- filterJust :: Arrow ar => ar (Event (Maybe a)) (Event a)
- filterLeft :: Arrow ar => ar (Event (Either a b)) (Event a)
- filterRight :: Arrow ar => ar (Event (Either a b)) (Event b)
- splitEvent :: Arrow ar => ar (Event (Either a b)) (Event a, Event b)
- evMap :: Arrow a => (b -> c) -> a (Event b) (Event c)
- newtype PlanT i o m a = PlanT {}
- type Plan i o a = forall m. Monad m => PlanT i o m a
- class MonadAwait m a | m -> a where
- class MonadYield m a | m -> a where
- class MonadStop m where
- catchP :: Monad m => PlanT i o m a -> PlanT i o m a -> PlanT i o m a
- stopped :: (Monad m, Occasional o) => ProcessT m i o
- muted :: (Monad m, Occasional' b, Occasional c) => ProcessT m b c
- constructT :: Monad m => PlanT i o m r -> ProcessT m (Event i) (Event o)
- repeatedlyT :: Monad m => PlanT i o m r -> ProcessT m (Event i) (Event o)
- construct :: Monad m => PlanT i o Identity r -> ProcessT m (Event i) (Event o)
- repeatedly :: Monad m => PlanT i o Identity r -> ProcessT m (Event i) (Event o)
- newtype Evolution i o m r = Evolution {
- runEvolution :: Cont (ProcessT m i o) r
- packProc :: (Monad m, Occasional o) => m (ProcessT m i o) -> ProcessT m i o
- awaitProc :: (Monad m, Occasional o) => (a -> ProcessT m (Event a) o) -> ProcessT m (Event a) o -> ProcessT m (Event a) o
- yieldProc :: Monad m => a -> ProcessT m i (Event a) -> ProcessT m i (Event a)
- runT :: (Monad m, Foldable f) => (c -> m ()) -> ProcessT m (Event b) (Event c) -> f b -> m ()
- runT_ :: (Monad m, Foldable f) => ProcessT m (Event a) (Event b) -> f a -> m ()
- run :: Foldable f => ProcessT Identity (Event a) (Event b) -> f a -> [b]
- run_ :: (Foldable f, ArrowApply a) => ProcessA a (Event b) (Event c) -> a (f b) ()
- stepRun :: (Monad m, Monad m') => (forall p. m p -> m' p) -> (b -> m' ()) -> (Maybe a -> m' ()) -> ProcessT m (Event a) (Event b) -> a -> m' (ProcessT m (Event a) (Event b))
- stepYield :: (Monad m, Monad m') => (forall p. m p -> m' p) -> m' a -> m' () -> ProcessT m (Event a) (Event b) -> m' (Maybe b, ProcessT m (Event a) (Event b))
- switch :: Monad m => ProcessT m b (c, Event t) -> (t -> ProcessT m b c) -> ProcessT m b c
- dSwitch :: Monad m => ProcessT m b (c, Event t) -> (t -> ProcessT m b c) -> ProcessT m b c
- rSwitch :: Monad m => ProcessT m b c -> ProcessT m (b, Event (ProcessT m b c)) c
- drSwitch :: Monad m => ProcessT m b c -> ProcessT m (b, Event (ProcessT m b c)) c
- kSwitch :: Monad m => ProcessT m b c -> ProcessT m (b, c) (Event t) -> (ProcessT m b c -> t -> ProcessT m b c) -> ProcessT m b c
- dkSwitch :: Monad m => ProcessT m b c -> ProcessT m (b, c) (Event t) -> (ProcessT m b c -> t -> ProcessT m b c) -> ProcessT m b c
- gSwitch :: Monad m => ProcessT m b (p, r) -> ProcessT m p q -> ProcessT m (q, r) (c, Event t) -> (ProcessT m p q -> t -> ProcessT m b c) -> ProcessT m b c
- dgSwitch :: Monad m => ProcessT m b (p, r) -> ProcessT m p q -> ProcessT m (q, r) (c, Event t) -> (ProcessT m p q -> t -> ProcessT m b c) -> ProcessT m b c
- pSwitch :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m (b, col c) (Event mng) -> (col (ProcessT m ext c) -> mng -> ProcessT m b (col c)) -> ProcessT m b (col c)
- pSwitchB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m (b, col c) (Event mng) -> (col (ProcessT m b c) -> mng -> ProcessT m b (col c)) -> ProcessT m b (col c)
- dpSwitch :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m (b, col c) (Event mng) -> (col (ProcessT m ext c) -> mng -> ProcessT m b (col c)) -> ProcessT m b (col c)
- dpSwitchB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m (b, col c) (Event mng) -> (col (ProcessT m b c) -> mng -> ProcessT m b (col c)) -> ProcessT m b (col c)
- rpSwitch :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m (b, Event (col (ProcessT m ext c) -> col (ProcessT m ext c))) (col c)
- rpSwitchB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m (b, Event (col (ProcessT m b c) -> col (ProcessT m b c))) (col c)
- drpSwitch :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m (b, Event (col (ProcessT m ext c) -> col (ProcessT m ext c))) (col c)
- drpSwitchB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m (b, Event (col (ProcessT m b c) -> col (ProcessT m b c))) (col c)
- par :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m b (col c)
- parB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m b (col c)
- fit :: (Monad m, Monad m') => (forall p. m p -> m' p) -> ProcessT m b c -> ProcessT m' b c
- fitW :: (Monad m, Monad m', Functor w) => (forall p. w p -> p) -> (forall p q. (p -> m q) -> w p -> m' q) -> ProcessT m b c -> ProcessT m' (w b) c
- unsafeExhaust :: (Monad m, Foldable f) => (b -> m (f c)) -> ProcessT m b (Event c)
Stream transducer type
The stream transducer arrow.
To construct ProcessT
instances, use Plan
,
arr
, functions declared in Utils
,
or arrow combinations of them.
See an introduction at Control.Arrow.Machine documentation.
Monad m => Arrow (ProcessT m) Source # | |
Monad m => ArrowChoice (ProcessT m) Source # | |
Monad m => ArrowLoop (ProcessT m) Source # | |
Monad m => Profunctor (ProcessT m) Source # | |
Monad m => Category * (ProcessT m) Source # | |
Monad m => Functor (ProcessT m i) Source # | |
Monad m => Applicative (ProcessT m i) Source # | |
(Monad m, Semigroup o) => Semigroup (ProcessT m i o) Source # | |
(Monad m, Monoid o) => Monoid (ProcessT m i o) Source # | |
type ProcessA a = ProcessT (ArrowMonad a) Source #
Isomorphic to ProcessT when a
is ArrowApply.
Event type and utility
class Occasional' a where Source #
Signals that can be absent(NoEvent
) or end.
For composite structure, collapse
can be defined as monoid sum of all member occasionals.
Occasional' ZeroEvent Source # | |
Occasional' (Event a) Source # | |
(Occasional' a, Occasional' b) => Occasional' (a, b) Source # | |
class Occasional' a => Occasional a where Source #
Occasional signals with creation methods.
Occasional (Event a) Source # | |
(Occasional a, Occasional b) => Occasional (a, b) Source # | |
Discrete events on a time line. Created and consumed by various transducers.
Functor Event Source # | |
Semigroup a => Semigroup (Event a) Source # | |
Semigroup a => Monoid (Event a) Source # | |
Occasional (Event a) Source # | |
Occasional' (Event a) Source # | |
Monad m => MonadYield (Evolution i (Event a) m) a Source # | |
(Monad m, Occasional o) => MonadAwait (Evolution (Event a) o m) a Source # | |
noEvent :: Occasional a => a Source #
end :: Occasional a => a Source #
filterLeft :: Arrow ar => ar (Event (Either a b)) (Event a) Source #
Split an event stream.
>>>
run (filterLeft) [Left 1, Right 2, Left 3, Right 4]
[1,3]
filterRight :: Arrow ar => ar (Event (Either a b)) (Event b) Source #
Split an event stream.
>>>
run filterRight [Left 1, Right 2, Left 3, Right 4]
[2,4]
splitEvent :: Arrow ar => ar (Event (Either a b)) (Event a, Event b) Source #
Split an event stream.
>>>
run (splitEvent >>> arr fst) [Left 1, Right 2, Left 3, Right 4]
[1,3]
>>>
run (splitEvent >>> arr snd) [Left 1, Right 2, Left 3, Right 4]
[2,4]
evMap :: Arrow a => (b -> c) -> a (Event b) (Event c) Source #
Alias of "arr . fmap"
While "ProcessT a (Event b) (Event c)" means a transducer from b to c, function b->c can be lifted into a transducer by fhis function.
But in most cases you needn't call this function in proc-do notations,
because arr
s are completed automatically while desugaring.
For example,
proc x -> returnA -< f <$> x
is equivalent to
evMap f
Coroutine monad
Procedural coroutine monad that can await or yield values.
Coroutines can be encoded to machines by constructT
or so on and
then put into ProcessT
compositions.
newtype PlanT i o m a Source #
MonadWriter w m => MonadWriter w (PlanT i o m) Source # | |
MonadState s m => MonadState s (PlanT i o m) Source # | |
MonadReader r m => MonadReader r (PlanT i o m) Source # | |
MonadTrans (PlanT i o) Source # | |
Monad (PlanT i o m) Source # | |
Functor (PlanT i o m) Source # | |
Applicative (PlanT i o m) Source # | |
MonadIO m => MonadIO (PlanT i o m) Source # | |
Monad m => Alternative (PlanT i o m) Source # | |
Monad m => MonadPlus (PlanT i o m) Source # | |
Monad m => MonadStop (PlanT i o m) Source # | |
Monad m => MonadYield (PlanT i o m) o Source # | |
Monad m => MonadAwait (PlanT i o m) i Source # | |
class MonadAwait m a | m -> a where Source #
Monad m => MonadAwait (PlanT i o m) i Source # | |
(Monad m, Occasional o) => MonadAwait (Evolution (Event a) o m) a Source # | |
class MonadYield m a | m -> a where Source #
muted :: (Monad m, Occasional' b, Occasional c) => ProcessT m b c Source #
Constructing machines from plans
Evolution monad
Time-evolution monad, or generalized plan monad.
newtype Evolution i o m r Source #
A monad type represents time evolution of ProcessT
Evolution | |
|
Occasional o => MonadTrans (Evolution i o) Source # | |
Monad (Evolution i o m) Source # | |
Functor (Evolution i o m) Source # | |
Applicative (Evolution i o m) Source # | |
(MonadIO m, Occasional o) => MonadIO (Evolution i o m) Source # | |
(Monad m, Occasional o) => MonadStop (Evolution i o m) Source # | |
Monad m => MonadYield (Evolution i (Event a) m) a Source # | |
(Monad m, Occasional o) => MonadAwait (Evolution (Event a) o m) a Source # | |
awaitProc :: (Monad m, Occasional o) => (a -> ProcessT m (Event a) o) -> ProcessT m (Event a) o -> ProcessT m (Event a) o Source #
Running machines (at once)
runT :: (Monad m, Foldable f) => (c -> m ()) -> ProcessT m (Event b) (Event c) -> f b -> m () Source #
Run a machine.
runT_ :: (Monad m, Foldable f) => ProcessT m (Event a) (Event b) -> f a -> m () Source #
Run a machine discarding all results.
Running machines (step-by-step)
:: (Monad m, Monad m') | |
=> (forall p. m p -> m' p) | Lifting function (pass |
-> (b -> m' ()) | Callback on every output value. |
-> (Maybe a -> m' ()) | Callback on termination. |
-> ProcessT m (Event a) (Event b) | The machine to run. |
-> a | The argument to the machine. |
-> m' (ProcessT m (Event a) (Event b)) |
Execute until an input consumed and the machine suspends.
During the execution, the machine may yield values or stops. It can be handled by two callbacks.
In some case the machine failed to consume the input value. If so, the value is passed to the termination callback.
:: (Monad m, Monad m') | |
=> (forall p. m p -> m' p) | Lifting function (pass |
-> m' a | Callback on input value request. |
-> m' () | Callback on termination |
-> ProcessT m (Event a) (Event b) | The machine to run. |
-> m' (Maybe b, ProcessT m (Event a) (Event b)) |
Execute until an output produced.
During the execution, the machine may await values or stops. It can be handled by two callbacks.
If the machine stops without producing any value,
The first element of the return tuple is Nothing
.
Primitive machines - switches
Switches inspired by the Yampa library.
Signature is almost same, but collection requirement is not only Functor
,
but Traversable
. This is because of side effects.
switch :: Monad m => ProcessT m b (c, Event t) -> (t -> ProcessT m b c) -> ProcessT m b c Source #
Run the 1st transducer at the beggining. Then switch to 2nd when Event t occurs.
>>>
:{
let before = proc x -> do trigger <- filterEvent (== 3) -< x returnA -< ((*10) <$> x, trigger) after t = proc x -> returnA -< (*100) <$> x in run (switch before after) [1..5] :} [10,20,300,400,500]
dSwitch :: Monad m => ProcessT m b (c, Event t) -> (t -> ProcessT m b c) -> ProcessT m b c Source #
Delayed version of switch
>>>
:{
let before = proc x -> do trigger <- filterEvent (== 3) -< x returnA -< ((*10) <$> x, trigger) after t = proc x -> returnA -< (*100) <$> x in run (dSwitch before after) [1..5] :} [10,20,30,400,500]
rSwitch :: Monad m => ProcessT m b c -> ProcessT m (b, Event (ProcessT m b c)) c Source #
Recurring switch.
>>>
:{
let pa = proc evtp -> do evx <- returnA -< fst <$> evtp evarr <- filterJust -< snd <$> evtp rSwitch (evMap (*10)) -< (evx, evarr) l = [(1, Nothing), (2, Just (arr $ fmap (*100))), (3, Nothing), (4, Just (arr $ fmap (*1000))), (5, Nothing)] in run pa l :} [10,200,300,4000,5000]
drSwitch :: Monad m => ProcessT m b c -> ProcessT m (b, Event (ProcessT m b c)) c Source #
Delayed version of rSwitch
.
>>>
:{
let pa = proc evtp -> do evx <- returnA -< fst <$> evtp evarr <- filterJust -< snd <$> evtp drSwitch (evMap (*10)) -< (evx, evarr) l = [(1, Nothing), (2, Just (arr $ fmap (*100))), (3, Nothing), (4, Just (arr $ fmap (*1000))), (5, Nothing)] in run pa l :} [10,20,300,400,5000]
kSwitch :: Monad m => ProcessT m b c -> ProcessT m (b, c) (Event t) -> (ProcessT m b c -> t -> ProcessT m b c) -> ProcessT m b c Source #
dkSwitch :: Monad m => ProcessT m b c -> ProcessT m (b, c) (Event t) -> (ProcessT m b c -> t -> ProcessT m b c) -> ProcessT m b c Source #
gSwitch :: Monad m => ProcessT m b (p, r) -> ProcessT m p q -> ProcessT m (q, r) (c, Event t) -> (ProcessT m p q -> t -> ProcessT m b c) -> ProcessT m b c Source #
dgSwitch :: Monad m => ProcessT m b (p, r) -> ProcessT m p q -> ProcessT m (q, r) (c, Event t) -> (ProcessT m p q -> t -> ProcessT m b c) -> ProcessT m b c Source #
pSwitch :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m (b, col c) (Event mng) -> (col (ProcessT m ext c) -> mng -> ProcessT m b (col c)) -> ProcessT m b (col c) Source #
pSwitchB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m (b, col c) (Event mng) -> (col (ProcessT m b c) -> mng -> ProcessT m b (col c)) -> ProcessT m b (col c) Source #
dpSwitch :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m (b, col c) (Event mng) -> (col (ProcessT m ext c) -> mng -> ProcessT m b (col c)) -> ProcessT m b (col c) Source #
dpSwitchB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m (b, col c) (Event mng) -> (col (ProcessT m b c) -> mng -> ProcessT m b (col c)) -> ProcessT m b (col c) Source #
rpSwitch :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m (b, Event (col (ProcessT m ext c) -> col (ProcessT m ext c))) (col c) Source #
rpSwitchB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m (b, Event (col (ProcessT m b c) -> col (ProcessT m b c))) (col c) Source #
drpSwitch :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m (b, Event (col (ProcessT m ext c) -> col (ProcessT m ext c))) (col c) Source #
drpSwitchB :: (Monad m, Traversable col) => col (ProcessT m b c) -> ProcessT m (b, Event (col (ProcessT m b c) -> col (ProcessT m b c))) (col c) Source #
par :: (Monad m, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessT m ext c) -> ProcessT m b (col c) Source #
Primitive machines - other safe primitives
fit :: (Monad m, Monad m') => (forall p. m p -> m' p) -> ProcessT m b c -> ProcessT m' b c Source #
Natural transformation
fitW :: (Monad m, Monad m', Functor w) => (forall p. w p -> p) -> (forall p q. (p -> m q) -> w p -> m' q) -> ProcessT m b c -> ProcessT m' (w b) c Source #
Experimental: more general fit.
Should w be a comonad?