machines-0.2.1.3: Networked stream transducers

PortabilityRank-N Types, MPTCs
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Inferred

Data.Machine.Plan

Contents

Description

 

Synopsis

Plans

type Plan k o a = forall m. PlanT k o m aSource

A Plan k o a is a specification for a pure Machine, that reads inputs selected by k with types based on i, writes values of type o, and has intermediate results of type a.

A PlanT k o a can be used as a PlanT k o m a for any Monad m.

It is perhaps easier to think of Plan in its un-cps'ed form, which would look like:

 data Plan k o a
   = Done a
   | Yield o (Plan k o a)
   | forall z. Await (z -> Plan k o a) (k z) (Plan k o a)
   | Fail

runPlan :: PlanT k o Identity a -> (a -> r) -> (o -> r -> r) -> (forall z. (z -> r) -> k z -> r -> r) -> r -> rSource

Deconstruct a Plan without reference to a Monad.

newtype PlanT k o m a Source

You can construct a Plan (or PlanT), turning it into a Machine (or MachineT).

Constructors

PlanT 

Fields

runPlanT :: forall r. (a -> m r) -> (o -> m r -> m r) -> (forall z. (z -> m r) -> k z -> m r -> m r) -> m r -> m r
 

Instances

(Monad (PlanT k o m), MonadError e m) => MonadError e (PlanT k o m) 
(Monad (PlanT k o m), MonadReader e m) => MonadReader e (PlanT k o m) 
(Monad (PlanT k o m), MonadState s m) => MonadState s (PlanT k o m) 
(Monoid w, Monad (PlanT k o m), MonadWriter w m) => MonadWriter w (PlanT k o m) 
MonadTrans (PlanT k o) 
Monad (PlanT k o m) 
Functor (PlanT k o m) 
Monad (PlanT k o m) => MonadPlus (PlanT k o m) 
Functor (PlanT k o m) => Applicative (PlanT k o m) 
Applicative (PlanT k o m) => Alternative (PlanT k o m) 
(Monad (PlanT k o m), MonadIO m) => MonadIO (PlanT k o m) 

yield :: o -> Plan k o ()Source

Output a result.

await :: Category k => Plan (k i) o iSource

Wait for input.

await = awaits id

awaits :: k i -> Plan k o iSource

Wait for a particular input.

 awaits L  :: Plan (T a b) o a
 awaits R  :: Plan (T a b) o b
 awaits id :: Plan (Is i) o i