machinecell-3.3.1: Arrow based stream transducers

Safe HaskellTrustworthy
LanguageHaskell2010

Control.Arrow.Machine.Types

Contents

Synopsis

Stream transducer type

data ProcessA a b c

The stream transducer arrow.

To construct ProcessA instances, use Plan, arr, functions declared in Utils, or arrow combinations of them.

See an introduction at Control.Arrow.Machine documentation.

Event type and utility

class Occasional' a where

Signals that can be absent(NoEvent) or end. For composite structure, collapse can be defined as monoid sum of all member occasionals.

Methods

collapse :: a -> Event ()

Instances

class Occasional' a => Occasional a where

Occasional signals with creation methods.

Methods

noEvent :: a

end :: a

Instances

data Event a

Discrete events on a time line. Created and consumed by various transducers.

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)

Alias of "arr . fmap"

While "ProcessA 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 arrs 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 ProcessA compositions.

newtype PlanT i o m a

Constructors

PlanT 

Fields

freePlanT :: FT (PlanF i o) m a
 

Instances

MonadReader r m => MonadReader r (PlanT i o m) 
MonadState s m => MonadState s (PlanT i o m) 
MonadWriter w m => MonadWriter w (PlanT i o m) 
MonadTrans (PlanT i o) 
Monad (PlanT i o m) 
Functor (PlanT i o m) 
Applicative (PlanT i o m) 
Alternative m => Alternative (PlanT i o m) 
(Monad m, Alternative m) => MonadPlus (PlanT i o m) 

type Plan i o a = forall m. Monad m => PlanT i o m a

await :: Plan i o i

yield :: o -> Plan i o ()

stop :: Plan i o a

catchP :: Monad m => PlanT i o m a -> PlanT i o m a -> PlanT i o m a

Constructing machines from plans

constructT :: (Monad m, ArrowApply a) => (forall b. m b -> a () b) -> PlanT i o m r -> ProcessA a (Event i) (Event o)

repeatedlyT :: (Monad m, ArrowApply a) => (forall b. m b -> a () b) -> PlanT i o m r -> ProcessA a (Event i) (Event o)

Running machines (at once)

run :: ArrowApply a => ProcessA a (Event b) (Event c) -> a [b] [c]

Run a machine.

runOn :: (ArrowApply a, Monoid r, Foldable f) => (c -> r) -> ProcessA a (Event b) (Event c) -> a (f b) r

Run a machine with results concatenated in terms of a monoid.

run_ :: ArrowApply a => ProcessA a (Event b) (Event c) -> a [b] ()

Run a machine discarding all results.

Running machines (step-by-step)

data ExecInfo fa

Represents return values and informations of step executions.

Constructors

ExecInfo 

Fields

yields :: fa

Values yielded while the step.

hasConsumed :: Bool

True if the input value is consumed.

False if the machine has stopped unless consuming the input.

Or in the case of stepYield, this field become false when the machine produces a value unless consuming the input.

hasStopped :: Bool

True if the machine has stopped at the end of the step.

Instances

Eq fa => Eq (ExecInfo fa) 
Show fa => Show (ExecInfo fa) 
Alternative f => Monoid (ExecInfo (f a)) 

stepRun :: ArrowApply a => ProcessA a (Event b) (Event c) -> a b (ExecInfo [c], ProcessA a (Event b) (Event c))

Execute until an input consumed and the machine suspends.

stepYield :: ArrowApply a => ProcessA a (Event b) (Event c) -> a b (ExecInfo (Maybe c), ProcessA a (Event b) (Event c))

Execute until an output produced.

Primitive machines - switches

Switches inspired by Yampa library. Signature is almost same, but collection requirement is not only Functor, but Traversable. This is because of side effects.

switch :: ArrowApply a => ProcessA a b (c, Event t) -> (t -> ProcessA a b c) -> ProcessA a b c

dSwitch :: ArrowApply a => ProcessA a b (c, Event t) -> (t -> ProcessA a b c) -> ProcessA a b c

rSwitch :: ArrowApply a => ProcessA a b c -> ProcessA a (b, Event (ProcessA a b c)) c

drSwitch :: ArrowApply a => ProcessA a b c -> ProcessA a (b, Event (ProcessA a b c)) c

kSwitch :: ArrowApply a => ProcessA a b c -> ProcessA a (b, c) (Event t) -> (ProcessA a b c -> t -> ProcessA a b c) -> ProcessA a b c

dkSwitch :: ArrowApply a => ProcessA a b c -> ProcessA a (b, c) (Event t) -> (ProcessA a b c -> t -> ProcessA a b c) -> ProcessA a b c

gSwitch :: ArrowApply a => ProcessA a b (p, r) -> ProcessA a p q -> ProcessA a (q, r) (c, Event t) -> (ProcessA a p q -> t -> ProcessA a b c) -> ProcessA a b c

dgSwitch :: ArrowApply a => ProcessA a b (p, r) -> ProcessA a p q -> ProcessA a (q, r) (c, Event t) -> (ProcessA a p q -> t -> ProcessA a b c) -> ProcessA a b c

pSwitch :: (ArrowApply a, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessA a ext c) -> ProcessA a (b, col c) (Event mng) -> (col (ProcessA a ext c) -> mng -> ProcessA a b (col c)) -> ProcessA a b (col c)

pSwitchB :: (ArrowApply a, Traversable col) => col (ProcessA a b c) -> ProcessA a (b, col c) (Event mng) -> (col (ProcessA a b c) -> mng -> ProcessA a b (col c)) -> ProcessA a b (col c)

dpSwitch :: (ArrowApply a, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessA a ext c) -> ProcessA a (b, col c) (Event mng) -> (col (ProcessA a ext c) -> mng -> ProcessA a b (col c)) -> ProcessA a b (col c)

dpSwitchB :: (ArrowApply a, Traversable col) => col (ProcessA a b c) -> ProcessA a (b, col c) (Event mng) -> (col (ProcessA a b c) -> mng -> ProcessA a b (col c)) -> ProcessA a b (col c)

rpSwitch :: (ArrowApply a, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessA a ext c) -> ProcessA a (b, Event (col (ProcessA a ext c) -> col (ProcessA a ext c))) (col c)

rpSwitchB :: (ArrowApply a, Traversable col) => col (ProcessA a b c) -> ProcessA a (b, Event (col (ProcessA a b c) -> col (ProcessA a b c))) (col c)

drpSwitch :: (ArrowApply a, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessA a ext c) -> ProcessA a (b, Event (col (ProcessA a ext c) -> col (ProcessA a ext c))) (col c)

drpSwitchB :: (ArrowApply a, Traversable col) => col (ProcessA a b c) -> ProcessA a (b, Event (col (ProcessA a b c) -> col (ProcessA a b c))) (col c)

par :: (ArrowApply a, Traversable col) => (forall sf. b -> col sf -> col (ext, sf)) -> col (ProcessA a ext c) -> ProcessA a b (col c)

parB :: (ArrowApply a, Traversable col) => col (ProcessA a b c) -> ProcessA a b (col c)

Primitive machines - other safe primitives

fit :: (ArrowApply a, ArrowApply a') => (forall p q. a p q -> a' p q) -> ProcessA a b c -> ProcessA a' b c

Natural transformation

fitW :: (ArrowApply a, ArrowApply a', Functor w) => (forall p. w p -> p) -> (forall p q. a p q -> a' (w p) q) -> ProcessA a b c -> ProcessA a' (w b) c

Experimental: more general fit.

Should w be a comonad?

Primitive machines - unsafe

unsafeExhaust :: (ArrowApply a, Foldable f) => a b (f c) -> ProcessA a b (Event c)

Repeatedly call p.

How many times p is called is indefinite. So p must satisfy the equation below;

p &&& (p >>> arr null) === p &&& arr (const True)

where

null = getAll . foldMap (_ -> All False)