j [      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ &(C) 2012 Edward Kmett, Rnar Bjarnason BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalRank-N Types, MPTCsSafe9;<=OT A  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  k o a can be used as a  k o m a for any  m.!It is perhaps easier to think of / in its un-cps'ed form, which would look like: data m 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 You can  construct a  (or ), turning it into a  (or ).Deconstruct a  without reference to a .Output a result.7Like yield, except stops if there is no value to yield.Wait for input.  =  Wait for a particular input. awaits L ::  (T a b) o a awaits R ::  (T a b) o b awaits  ::  ( i) o i   =  ORun a monadic action repeatedly yielding its results, until it returns Nothing.      (C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisional rank-2, GADTsNone%&9;OTDAn input type that supports merging requests from multiple machines.A E reads from a number of inputs and may yield results before stopping.A  can be used as a  m for any  m.A ` reads from a number of inputs and may yield results before stopping with monadic side-effects.This is the base functor for a  or .Note: A  is usually constructed from ", so it does not need to be CPS'd.   =  . !Pack a  of a  into a ." Transform a - by looking at a single step of that machine.#7Stop feeding input into model, taking only the effects.$3Stop feeding input into model and extract an answer%)Run a pure machine and extract an answer.&$Connect different kinds of machines. &  = (Compile a machine to a model.)MGenerates a model that runs a machine until it stops, then start it up again. ) m = ( ( m)*(Unfold a stateful PlanT into a MachineT.+ZEvaluate a machine until it stops, and then yield answers according to the supplied model.,Incorporate a  into the resulting machine.-OGiven a handle, ignore all other inputs and just stream input from that handle. -  ::  a a -   ::   a b a -   ::   a b b -   ::   a b a -   ::   a b b -   ::   a b (Either a b) .KRun a machine with no input until it stops, then behave as another machine./This is a stopped 1GUse a predicate to mark a yielded value as the terminal value of this %. This is useful in combination with 0 to combine s.2OUse a function to produce and mark a yielded value as the terminal value of a ;. All yielded values for which the given function returns V are yielded down the pipeline, but the first value for which the function returns a  value will be returned by a  created via 0.3,This permits toList to be used on a Machine.$ !"#$%&'()*+,-./0123456789 !"#$%&'()*+,-./012#$% !()*+,012&'-./" !"#$%&'()*+,-./0123456789None:HRight fold over a stream. This will be lazy if the underlying monad is. runT = foldrT (:) [];Strict left fold over a stream.<>Strict fold over a stream. Items are accumulated on the right:  ... ((f o1 <> f o2) <> f o3) ...5Where this is expensive, use the dual monoid instead.=FStrict fold over a monoid stream. Items are accumulated on the right: ... ((o1 <> o2) <> o3) ...5Where this is expensive, use the dual monoid instead. foldT = foldMapT id>Run a machine with no input until it yields for the first time, then stop it. This is intended primarily for use with accumulating machines, such as the ones produced by fold or fold1 runT1 m = getFirst  $( foldMapT (First . Just) (m ~> taking 1):;<=>#$:;<=>:;<=>$#:;<=>(C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalGADTsNone%&OT?@This is a simple process type that knows how to push back input.B?Peek at the next value in the input stream without consuming itCPush back into the input streamD&Pop the next value in the input streamEStream outputs from one ; into another with the possibility of pushing inputs back.?@ABCDE?@ABCDE?@AEBDC?@ABCDE'(C) 2015 Yorick Laupa, Gabriel Gonzalez BSD-style (see the file LICENSE)!Yorick Laupa <yo.eight@gmail.com> provisionalRank-2 Types, GADTsNone%&OTFLike J, but with a polymorphic typeGLike I, but with a polymorphic typeHLike K, but with a polymorphic typeI Server b' b receives requests of type b' and sends responses of type b. Is only Q and never P.J Client a' a sends requests of type a'# and receives responses of type a. Js only P and never Q.KK s neither P nor QPLSend a value of type a' upstream and block waiting for a reply of type a. P) is the identity of the request category.QMSend a value of type a downstream and block waiting for a reply of type a' Q) is the identity of the respond category.R+Forward responses followed by requests. R& is the identity of the push category.S"Compose two proxies blocked while P0ing data, creating a new proxy blocked while Ping data. (S3) is the composition operator of the push category.T(p >>~ f) pairs each Q in p with an P in f.U+Forward requests followed by responses. U& is the identity of the pull category.V-Compose two proxies blocked in the middle of Q6ing, creating a new proxy blocked in the middle of Q ing. (V3) is the composition operator of the pull category.W(f +>> p) pairs each P in p with a Q in f.XIt is impossible for an M to hold a  value.YRun a self-contained K', converting it back to the base monad.ZLike Y# but discarding any produced value.FGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVWXYZMNOLKJIHGFPQRSTUVWXYZFGHIJKLMNOPQRSTUVWXYZS8T7V7W6None[Given an initial state and a  that runs in  s m , produce a  that runs in m.\\L allows a broken machine to be replaced without stopping the assembly line.]Given an environment and a  that runs in  e m , produce a  that runs in m.[\][\][\][\](C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalGADTs, Type FamiliesSafe%&DR^Witnessed type equality^_`abcde^_^_^_`abcde(C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalRank 2 Types, GADTsNone %&9;OT#hAn h$ can be automatically lifted into a kjA j m a b8 is a stream transducer that can consume values of type a- from its input, and produce values of type b and has side-effects in the  m.kA k a b8 is a stream transducer that can consume values of type a- from its input, and produce values of type b for its output.l The trivial k, that simply repeats each input it receives.*This can be constructed from a plan with H echo :: Process a a echo = repeatedly $ do i <- await yield i  Examples:run $ echo <~ source [1..5] [1,2,3,4,5]mA k! that prepends the elements of a 3 onto its input, then repeats its input from there.nA k8 that only passes through inputs that match a predicate.*This can be constructed from a plan with n filtered :: (a -> Bool) -> Process a a filtered p = repeatedly $ do i <- await when (p i) $ yield i  Examples:$run $ filtered even <~ source [1..5][2,4]oA k that drops the first n, then repeats the rest.*This can be constructed from a plan with 2 dropping n = before echo $ replicateM_ n await  Examples:!run $ dropping 3 <~ source [1..5][4,5]pA k that passes through the first n# elements from its input then stops*This can be constructed from a plan with : taking n = construct . replicateM_ n $ await >>= yield  Examples:run $ taking 3 <~ source [1..5][1,2,3]qA kJ that passes through elements until a predicate ceases to hold, then stops*This can be constructed from a plan with x takingWhile :: (a -> Bool) -> Process a a takingWhile p = repeatedly $ await >>= v -> if p v then yield v else stop  Examples:(run $ takingWhile (< 3) <~ source [1..5][1,2]rA k, that drops elements while a predicate holds*This can be constructed from a plan with  droppingWhile :: (a -> Bool) -> Process a a droppingWhile p = before echo loop where loop = await >>= v -> if p v then loop else yield v  Examples:*run $ droppingWhile (< 3) <~ source [1..5][3,4,5]sChunk up the input into n element lists.NAvoids returning empty lists and deals with the truncation of the final group.>An approximation of this can be constructed from a plan with  buffered :: Int -> Process a [a] buffered = repeatedly . go [] where go acc 0 = yield (reverse acc) go acc n = do i  -await <|5 yield (reverse acc) *> stop go (i:acc) $! n-1  Examples:!run $ buffered 3 <~ source [1..6][[1,2,3],[4,5,6]]!run $ buffered 3 <~ source [1..5][[1,2,3],[4,5]]run $ buffered 3 <~ source [][]t Build a new  by adding a k to the output of an old  (t) :: k b c -> k a b -> k a c (t) :: k c d ->   a b c ->   a b d (t) :: k b c ->  k b ->  k c u Flipped (t).vFeed a k some input. Examples:*run $ supply [1,2,3] echo <~ source [4..6] [1,2,3,4,5,6]w<Convert a machine into a process, with a little bit of help.  choose ::  - a b x -> (a, b) -> x choose t = case t of   ->    ->   w choose ::   a b c -> k (a, b) c w choose ::   a b c -> k (a, b) c w (  ) :: k a b -> k a b x Construct a k from a left-scanning operation.Like {#, but yielding intermediate values.9It may be useful to consider this alternative signature  x' :: (a -> b -> a) -> a -> Process b a  For stateful x use i with Data.Machine.Mealy5 machine. This can be constructed from a plan with  scan :: Category k => (a -> b -> a) -> a -> Machine (k b) a scan func seed = construct $ go seed where go cur = do yield cur next <- await go $! func cur next  Examples:!run $ scan (+) 0 <~ source [1..5][0,1,3,6,10,15]-run $ scan (\a _ -> a + 1) 0 <~ source [1..5] [0,1,2,3,4,5]yy is a variant of x$ that has no starting value argument*This can be constructed from a plan with  scan1 :: Category k => (a -> a -> a) -> Machine (k a) a scan1 func = construct $ await >>= go where go cur = do yield cur next <- await go $! func cur next  Examples: run $ scan1 (+) <~ source [1..5] [1,3,6,10,15]zLike xN only uses supplied function to map and uses Monoid for associative operation Examples:4run $ mapping getSum <~ scanMap Sum <~ source [1..5][0,1,3,6,10,15]{ Construct a k from a left-folding operation.Like x$, but only yielding the final value.9It may be useful to consider this alternative signature  {' :: (a -> b -> a) -> a -> Process b a *This can be constructed from a plan with  fold :: Category k => (a -> b -> a) -> a -> Machine (k b) a fold func seed = construct $ go seed where go cur = do next  -await <|- yield cur *> stop go $! func cur next  Examples:!run $ fold (+) 0 <~ source [1..5][15]-run $ fold (\a _ -> a + 1) 0 <~ source [1..5][5]|| is a variant of {$ that has no starting value argument*This can be constructed from a plan with  fold1 :: Category k => (a -> a -> a) -> Machine (k a) a fold1 func = construct $ await >>= go where go cur = do next  -await <|- yield cur *> stop go $! func cur next  Examples: run $ fold1 (+) <~ source [1..5][15]}CBreak each input into pieces that are fed downstream individually.*This can be constructed from a plan with ^ asParts :: Foldable f => Process (f a) a asParts = repeatedly $ await >>= traverse_ yield  Examples:'run $ asParts <~ source [[1..3],[4..6]] [1,2,3,4,5,6]~CBreak each input into pieces that are fed downstream individually. Alias for asPartssinkPart_ toParts sink" creates a process that uses the toParts) function to break input into a tuple of (passAlong, sinkPart); for which the second projection is given to the supplied sink jS (that produces no output) while the first projection is passed down the pipeline..Apply a monadic function to each element of a j.*This can be constructed from a plan with  autoM :: Monad m => (a -> m b) -> ProcessT m a b autoM :: (Category k, Monad m) => (a -> m b) -> MachineT m (k a) b autoM f = repeatedly $ await >>= lift . f >>= yield  Examples:"runT $ autoM Left <~ source [3, 4]Left 3#runT $ autoM Right <~ source [3, 4] Right [3,4]+Skip all but the final element of the input*This can be constructed from a plan with   :: ko a a final :: Category k => Machine (k a) a final = construct $ await >>= go where go prev = do next  -await <|" yield prev *> stop go next  Examples:runT $ final <~ source [1..10][10]runT $ final <~ source [][]aSkip all but the final element of the input. If the input is empty, the default value is emitted*This can be constructed from a plan with   :: a -> kn a a finalOr :: Category k => a -> Machine (k a) a finalOr = construct . go where go prev = do next  -await <|" yield prev *> stop go next  Examples:%runT $ finalOr (-1) <~ source [1..10][10] runT $ finalOr (-1) <~ source [][-1]8Intersperse an element between the elements of the input  :: a -> k a a 'Return the maximum value from the input'Return the minimum value from the input1Convert a stream of actions to a stream of values*This can be constructed from a plan with  sequencing :: Monad m => (a -> m b) -> ProcessT m a b sequencing :: (Category k, Monad m) => MachineT m (k (m a)) a sequencing = repeatedly $ do ma <- await a <- lift ma yield a  Examples:-runT $ sequencing <~ source [Just 3, Nothing]Nothing,runT $ sequencing <~ source [Just 3, Just 4] Just [3,4]4Apply a function to all values coming from the input*This can be constructed from a plan with f mapping :: Category k => (a -> b) -> Machine (k a) b mapping f = repeatedly $ await >>= yield . f  Examples:$runT $ mapping (*2) <~ source [1..3][2,4,6]7Apply an effectful to all values coming from the input. Alias to .Parse  Cable values, only emitting the value if the parse succceeds. This  stops at first parsing errorConvert  able values to  s mp mb Drops the given prefix from mp. It stops if mbT did not start with the prefix given, or continues streaming after the prefix, if mb did.)fghijklmnopqrstuvwxyz{|}~&fghijklmnopqrstuvwxyz{|}~&kjhifgwtulvmnoprqs~{|xyz}'fghijklmnopqrstuvwxyz{|}~t9 u9 (C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalportableNone<=DR machinesExamplesWe can enumerate inputs:;let countingMealy = unfoldMealy (\i x -> ((i, x), i + 1)) 0)run (auto countingMealy <~ source "word")![(0,'w'),(1,'o'),(2,'r'),(3,'d')]A % machine modeled with explicit state.$Fast forward a mealy machine forwardAccumulate history.slow diagonalization (C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalportableNone<=DR machines#Accumulate the input as a sequence.HConstruct a Moore machine from a state valuation and transition functionslow diagonalization (C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisional Rank-2 TypesNone9;OT A @ never reads from its inputs, but may have monadic side-effects.A  never reads from its inputs.%Repeat the same value, over and over.*This can be constructed from a plan with < repeated :: o -> Source o repeated = repeatedly . yield  Examples:run $ taking 5 <~ repeated 1 [1,1,1,1,1]Loop through a  container over and over.*This can be constructed from a plan with U cycled :: Foldable f => f b -> Source b cycled = repeatedly (traverse_ yield xs)  Examples:run $ taking 5 <~ cycled [1,2] [1,2,1,2,1] Generate a  from any  container.*This can be constructed from a plan with T source :: Foldable f => f b -> Source b source = construct (traverse_ yield xs)  Examples:run $ source [1,2][1,2]You can transform a  with a k.-Alternately you can view this as capping the  end of a k, yielding a new .  l r = l t rYou can transform any  into a , blocking its input.vThis is used by capT, and capWye, and allows an efficient way to plug together machines of different input languages. f x9 returns an infinite source of repeated applications of f to x n x is a source of x emitted n time(s)8Enumerate from a value to a final value, inclusive, via succ Examples:run $ enumerateFromTo 1 3[1,2,3] k seed| The function takes the element and returns Nothing if it is done producing values or returns Just (a,r), in which case, a is ed and r1 is used as the next element in a recursive call. Effectful  variant. 5(C) 2012 Edward Kmett, Rnar Bjarnason, Paul Chiusano BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalRank-2 Types, GADTsNone%&OTA Y that can read from two input stream in a deterministic manner with monadic side-effects.A ? that can read from two input stream in a deterministic manner.The input descriptor for a  or 0Compose a pair of pipes onto the front of a Tee. Examples:import Data.Machine.Source4run $ tee (source [1..]) (source ['a'..'c']) zipping[(1,'a'),(2,'b'),(3,'c')]`teeT mt ma mb` Use a ) to interleave or combine the outputs of ma and mb.5The resulting machine will draw from a single source. Examples:import Data.Machine.Source-run $ teeT zipping echo echo <~ source [1..5] [(1,2),(3,4)]/Precompose a pipe onto the left input of a tee.0Precompose a pipe onto the right input of a tee.>Tie off one input of a tee by connecting it to a known source.>Tie off one input of a tee by connecting it to a known source.Tie off both inputs to a tee by connecting them to known sources. This is recommended over capping each side separately, as it is far more efficient.Natural transformation used by  and .Mwait for both the left and the right sides of a T and then merge them with f.Zip together two inputs, then apply the given function, halting as soon as either input is exhausted. This implementation reads from the left, then the rightFZip together two inputs, halting as soon as either input is exhausted. 5(C) 2012 Edward Kmett, Rnar Bjarnason, Paul Chiusano BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisionalRank-2 Types, GADTsNone%&OT A ] that can read from two input stream in a non-deterministic manner with monadic side-effects.A C that can read from two input stream in a non-deterministic manner.The input descriptor for a  or ,Compose a pair of pipes onto the front of a . Precompose a k onto each input of a  (or ).=This is left biased in that it tries to draw values from the = input whenever they are available, and only draws from the  input when  would block./Precompose a pipe onto the left input of a wye.0Precompose a pipe onto the right input of a wye.>Tie off one input of a wye by connecting it to a known source.>Tie off one input of a wye by connecting it to a known source.ATie off both inputs of a wye by connecting them to known sources.Natural transformation used by  and   (C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> provisional non-portableNone  !"#$%&'()*+,-./012^_fghijklmnopqrstuvwxyz{|}~None%&TShare inputs with each of a list of processes in lockstep. Any values yielded by the processes are combined into a single yield from the composite process.Share inputs with each of a list of processes in lockstep. If none of the processes yields a value, the composite process will itself yield . The idea is to provide a handle on steps only executed for their side effects. For instance, if you want to run a collection of jus that await but don't yield some number of times, you can use 'fanOutSteps . map (fmap (const ()))' followed by a p process.None%&XUsing a function to signal group changes, apply a machine independently over each group.XMark a transition point between two groups as a function of adjacent elements. Examples%runT $ supply [1,2,2] (taggedBy (==))![Right 1,Left (),Right 2,Right 2]^Run a machine multiple times over partitions of the input stream specified by Left () values.Read inputs until a condition is met, then behave as cont with | input matching condition as first input of cont. | If await fails, stop... BSD-style (see the file LICENSE)NoneL machine, with monadic effectsembedMealyT Example:embedMealyT (arr (+1)) [1,2,3][2,3,4]Profunctor Example:8embedMealyT (dimap (+21) (+1) (arr (+1))) [1,2,3 :: Int] [24,25,26]  !!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklm_nopqrstuvwxyz{|}~                                      ! "# $%  & ' ( )  *+,-./%machines-0.6.2-ANN1G1QnspzGU6tjop91lYData.Machine.PlanData.Machine.TypeData.Machine.RunnerData.Machine.StackData.Machine.PipeData.Machine.LiftData.Machine.IsData.Machine.ProcessData.Machine.MealyData.Machine.MooreData.Machine.SourceData.Machine.TeeData.Machine.WyeData.Machine.FanoutData.Machine.GroupData.Machine.MealyTMachineMachineTIs Control.MonadforeverProcessLTeeRXWyeYZT Data.MachinePlanPlanTrunPlanTrunPlanyield maybeYieldawaitawaitsstopexhaust$fMonadErrorePlanT$fMonadWriterwPlanT$fMonadReaderePlanT$fMonadStatesPlanT$fMonadIOPlanT$fMonadTransPlanT$fMonadPlusPlanT $fMonadPlanT$fAlternativePlanT$fApplicativePlanT$fFunctorPlanT Applianceapplied runMachineTStepStopYieldAwait runMachineencased stepMachinerunT_runTrunfitfitM construct repeatedly unfoldPlanbeforepreplanpassstarvestopped deconstructtagDone finishWith$fFoldableMachineT$fApplicativeMachineT$fMonoidMachineT$fSemigroupMachineT$fPointedMachineT$fFunctorMachineT $fFunctorStepfoldrTfoldlTfoldMapTfoldTrunT1StackPushPoppeekpushpopstackClient'Server'Effect'ServerClientEffectProxyExchangeRequestRespondrequestrespond>~>>>~pull>+>+>>absurdExchange runEffect runEffect_ execStateM catchExcept runReaderMRefl$fCategoryTYPEIs$fReadIs $fMonoidIs$fOrdIs$fEqIs$fShowIs AutomatonMautoT AutomatonautoProcessTecho prependedfiltereddroppingtaking takingWhile droppingWhilebuffered<~~>supplyprocessscanscan1scanMapfoldfold1asParts flattened sinkPart_autoMfinalfinalOr intersperselargestsmallest sequencingmapping traversingreadingshowingstrippingPrefix$fAutomatonMKleisli $fAutomatonIs$fAutomaton(->)MealyrunMealy unfoldMealylogMealy $fClosedMealy$fMonadReaderNonEmptyMealy$fMonadZipMealy$fMonadFixMealy$fCorepresentableMealy$fCostrongMealy$fCosieveMealyNonEmpty$fRepresentableMealy$fDistributiveMealy$fArrowApplyMealy $fChoiceMealy $fStrongMealy$fArrowChoiceMealy $fArrowMealy$fCategoryTYPEMealy$fAutomatonMealy$fProfunctorMealy $fMonadMealy $fExtendMealy$fPointedMealy$fApplicativeMealy$fFunctorMealyMoorelogMoore unfoldMoore $fClosedMoore$fMonadReader[]Moore$fMonadZipMoore$fMonadFixMoore$fCorepresentableMoore$fCostrongMoore$fCosieveMoore[]$fRepresentableMoore$fDistributiveMoore$fComonadApplyMoore$fComonadMoore$fCopointedMoore $fMonadMoore$fPointedMoore$fApplicativeMoore$fProfunctorMoore$fFunctorMoore$fAutomatonMooreSourceTSourcerepeatedcycledsourcecapplugiterated replicatedenumerateFromTounfoldunfoldTTeeTteeteeTaddLaddRcapLcapRcapTzipWithTzipWithzippingWyeTwyeaddXaddYcapXcapYcapWyefanout fanoutSteps groupingOntaggedBy partitioning awaitUntilMealyT runMealyTarrPurearrMupgrade scanMealyT scanMealyTM embedMealyT$fAutomatonMMealyT $fArrowMealyT$fCategoryTYPEMealyT$fProfunctorMealyT $fMonadMealyT$fApplicativeMealyT$fPointedMealyT$fFunctorMealyTbaseGHC.BaseMonadControl.CategoryidemptyData.Functor.Identity runIdentityNothingJust Data.VoidVoidtransformers-0.5.2.0 Control.Monad.Trans.State.StrictStateTControl.Monad.Trans.ReaderReaderT Data.FoldableFoldable Data.TuplefstsndconstGHC.ReadReadGHC.ShowShowString driveMealycappedTcappedmemptycontinuesemigroupDlistisLeftautoMealyTImpl