machines-0.6.3: Networked stream transducers

Copyright(C) 2012 Edward Kmett Rúnar Bjarnason
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
PortabilityRank-N Types, MPTCs
Safe HaskellSafe
LanguageHaskell2010

Data.Machine.Plan

Contents

Description

 

Synopsis

Plans

type Plan k o a = forall m. PlanT k o m a Source #

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 Plan 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 -> r Source #

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

MonadState s m => MonadState s (PlanT k o m) Source # 

Methods

get :: PlanT k o m s #

put :: s -> PlanT k o m () #

state :: (s -> (a, s)) -> PlanT k o m a #

MonadReader e m => MonadReader e (PlanT k o m) Source # 

Methods

ask :: PlanT k o m e #

local :: (e -> e) -> PlanT k o m a -> PlanT k o m a #

reader :: (e -> a) -> PlanT k o m a #

MonadError e m => MonadError e (PlanT k o m) Source # 

Methods

throwError :: e -> PlanT k o m a #

catchError :: PlanT k o m a -> (e -> PlanT k o m a) -> PlanT k o m a #

MonadWriter w m => MonadWriter w (PlanT k o m) Source # 

Methods

writer :: (a, w) -> PlanT k o m a #

tell :: w -> PlanT k o m () #

listen :: PlanT k o m a -> PlanT k o m (a, w) #

pass :: PlanT k o m (a, w -> w) -> PlanT k o m a #

MonadTrans (PlanT k o) Source # 

Methods

lift :: Monad m => m a -> PlanT k o m a #

Monad (PlanT k o m) Source # 

Methods

(>>=) :: PlanT k o m a -> (a -> PlanT k o m b) -> PlanT k o m b #

(>>) :: PlanT k o m a -> PlanT k o m b -> PlanT k o m b #

return :: a -> PlanT k o m a #

fail :: String -> PlanT k o m a #

Functor (PlanT k o m) Source # 

Methods

fmap :: (a -> b) -> PlanT k o m a -> PlanT k o m b #

(<$) :: a -> PlanT k o m b -> PlanT k o m a #

MonadFail (PlanT k o m) Source # 

Methods

fail :: String -> PlanT k o m a #

Applicative (PlanT k o m) Source # 

Methods

pure :: a -> PlanT k o m a #

(<*>) :: PlanT k o m (a -> b) -> PlanT k o m a -> PlanT k o m b #

(*>) :: PlanT k o m a -> PlanT k o m b -> PlanT k o m b #

(<*) :: PlanT k o m a -> PlanT k o m b -> PlanT k o m a #

MonadIO m => MonadIO (PlanT k o m) Source # 

Methods

liftIO :: IO a -> PlanT k o m a #

Alternative (PlanT k o m) Source # 

Methods

empty :: PlanT k o m a #

(<|>) :: PlanT k o m a -> PlanT k o m a -> PlanT k o m a #

some :: PlanT k o m a -> PlanT k o m [a] #

many :: PlanT k o m a -> PlanT k o m [a] #

MonadPlus (PlanT k o m) Source # 

Methods

mzero :: PlanT k o m a #

mplus :: PlanT k o m a -> PlanT k o m a -> PlanT k o m a #

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

Output a result.

maybeYield :: Maybe o -> Plan k o () Source #

Like yield, except stops if there is no value to yield.

await :: Category k => Plan (k i) o i Source #

Wait for input.

await = awaits id

awaits :: k i -> Plan k o i Source #

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

exhaust :: Monad m => m (Maybe a) -> PlanT k a m () Source #

Run a monadic action repeatedly yielding its results, until it returns Nothing.