HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulemachines-0.7.4Haskell2010

Data.Machine.Plan

  • 2 types
  • 7 values
  • Packagemachines-0.7.4
  • Exports9
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePlan.hs

Plans

9 declarations
typetype Plan (k :: Type -> Type) o a = forall (m :: Type -> Type). PlanT k o m a
#

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
valuerunPlan
  1. :: PlanT k o Identity a
  2. -> a -> r
  3. -> o -> r -> r
  4. -> forall z. (z -> r) -> k z -> r -> r
  5. -> r
  6. -> r
#

Deconstruct a Plan without reference to a Monad.

newtypenewtype PlanT (k :: Type -> Type) o (m :: Type -> Type) a
#

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

Constructors

  • PlanT
    • 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
Instances12MonadError, MonadReader, MonadState, MonadWriter, MonadTrans, Monad, …
valueyield :: o -> Plan k o ()
#

Output a result.

valuemaybeYield :: Maybe o -> Plan k o ()
#

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

valueawaits :: k i -> Plan k o i
#

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
valueexhaust :: Monad m => m (Maybe a) -> PlanT k a m ()
#

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