úÎéTäyL      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKCommon definitions*© 2015 Patryk Zadarnowski <pat@jantar.org>BSD3pat@jantar.org experimentalportableSafeFIN A Quiver effectO, represented by a stream processor with unspecified input and output types. A Quiver consumerE, represented by a stream processor with unspecified output types. A Quiver producerD, represented by a stream processor with unspecified input types.The main Quiver stream processor type P a a' b b' f r, representing a producerconsumer structure with bidirectional/, bounded• communication on both the upstream (consumer) and downstream (producer) channel. The six type parameters have the following intuitive meaning:a is the type of a request€ values sent by the stream processor to its upstream partner in order to receive the next element of the input stream.a'y is the type of the actual information being consumed by this stream processor (i.e., elements of its input stream.)bz is the type of the actual information being produced by this stream processor (i.e., elements of its output stream.)b' is the type of the response values received from the downstream partner for each element of the output stream produced by this stream processor.f' is the type of the stream processor's  base functorz; usually this is a monad used for stateful stream processing, exception handling and/or real-world interaction.r is the stream processor's  delivery type4, used for monadic stream processor definition.\Every stream processor is a functor over its delivery type. However, if the base functor f) meets the additional requirements of L or Md, so will the stream processor itself. Note that, unlike most other stream processing libraries, f¡ is not required to be a monad in most applications, although only time will tell whether this generalisation has useful applications in the real world. Consume x k q represents a  consumer step, in which the request xE is sent upstream and the returned input value is supplied to the continuation processor k*, or, if the upstream partner has been depleted[ (i.e., delivered its ultimate result, hence reaching the end of processing), to the decoupled continuation q. Produce y k q represent a  producer step, in which the output value yL is sent downstream, and the returned acknowledgement is supplied to the continuation processor k), or, if the downstream partner has been  decoupled[ (i.e., delivered its ultimate result, hence reaching the end of processing), to the depleted continuation q.Enclose9 allows for selective application of the base functor f& the the remainder of the computation. Deliver rH completes processing of information, delivering its ultimate result r. consume x k q represents a  consumer step, in which the request xE is sent upstream and the returned input value is supplied to the continuation processor k*, or, if the upstream partner has been depleted[ (i.e., delivered its ultimate result, hence reaching the end of processing), to the decoupled continuation q.  produce y k q represent a  producer step, in which the output value yL is sent downstream, and the returned acknowledgement is supplied to the continuation processor k), or, if the downstream partner has been  decoupled[ (i.e., delivered its ultimate result, hence reaching the end of processing), to the depleted continuation q. enclose9 allows for selective application of the base functor f& the the remainder of the computation.  deliver rH completes processing of information, delivering its ultimate result r.  decouple p  decouples the stream processor p-, by replacing the first consumer step in pC with that step's decoupled contination, effectively converting pJ into a producer processor that no longer expects to receive any input.  deplete p depletes the stream processor p-, by replacing the first producer step in pB with that step's depleted contination, effectively converting pF into a consumer processor that will never produce any more output.FLifts the value of a base functor into a stream processor; same as N from O8, but relaxing constraint on the base structure from M to P.qMorphs the value of a base functor into another functor by applying the supplied functor morphism to every % step of a stream processor; same as Q from R; but relaxing the constraint on the base structure from M to P.<Embeds a monad within another monad transformer; same as S from T. UVWXYZ[   UVWXYZ[(Monad transformers for quiver processors*© 2015 Patryk Zadarnowski <pat@jantar.org>BSD3pat@jantar.org experimentalportableSafeIN IHoists a stream processor from an 'ErrorT e m' monad into its base monad m.JHoists a stream processor from an 'ExceptT e m' monad into its base monad m.FHoists a stream processor from a 'MaybeT m' monad into its base monad m.OHoists a stream processor from a lazy 'RWST r w s m' monad into its base monad m.OHoists a stream processor from a lazy 'RWST r w s m' monad into its base monad m.QHoists a stream processor from a strict 'RWST r w s m' monad into its base monad m.IHoists a stream processor from a 'ReaderT r m' monad into its base monad m.MHoists a stream processor from a lazy 'StateT s m' monad into its base monad m.MHoists a stream processor from a lazy 'StateT s m' monad into its base monad m.OHoists a stream processor from a strict 'StateT s m' monad into its base monad m.NHoists a stream processor from a lazy 'WriterT w m' monad into its base monad m.NHoists a stream processor from a lazy 'WriterT w m' monad into its base monad m.PHoists a stream processor from a strict 'WriterT w m' monad into its base monad m.    Core Quiver definitions*© 2015 Patryk Zadarnowski <pat@jantar.org>BSD3pat@jantar.org experimentalportableNoneFINfetch xI represents a singleton stream processor that sends the request value x< upstream and delivers the next input value received, or Nothing0 if the upstream processor has been depleted.fetch_ xI represents a singleton stream processor that sends the request value x? upstream, discarding any input received, for symmetry with emit_. emit yP represents a singleton stream processor that produces a single output value yL and delivers the response received from the downstream processor, or Nothing0 if the downstream processor has been decoupled.!emit_ yP represents a singleton stream processor that produces a single output value yB, ignoring any response received from the downstream processor." qpure g f zE produces an infinite consumer/producer that uses a pure function f5 to convert every input value into an output, and fw to convert each downstream response value into an upstream request; the initial request is obtained by applying g to the initial response value z.#=A pull-based identity processor, equivalent to 'qpure id id'.$šA pull-based list flattening processor, delivering the list of inputs that could not be produced and a list of responses that could not be consumed.% Evaluates an effect°, i.e., a processor that is both detached and depleted and hence neither consumes nor produces any input, returning its delivered value. The base functor must be a monad.&The >>->> represents a push-based composition of stream processors.  p1 >>-> p2> represents a stream processor that forwards the output of p1 to p2D, delivering the result of both processors. The new processor is driven by p2P, so, if the base functor represents a non-commutative monad, any effects of p2% will be observed before those of p1.'The +>>->p represents a pull-based composition of stream processors that is partial on the left (supply) side, so that  p1 +>>-> p2> represents a stream processor that forwards the output of p1 to p2, delivering the result of p2. and the remainder (unconsumed portion) of p1. The new processor is driven by p1P, so, if the base functor represents a non-commutative monad, any effects of p1% will be observed before those of p2.(The >>->+q represents a pull-based composition of stream processors that is partial on the right (demand) side, so that  p1 >>->+ p2> represents a stream processor that forwards the output of p1 to p2, delivering the result of p1. and the remainder (unproduced portion) of p2. The new processor is driven by p1P, so, if the base functor represents a non-commutative monad, any effects of p1% will be observed before those of p2.)The >->>> represents a pull-based composition of stream processors.  p1 >->> p2> represents a stream processor that forwards the output of p1 to p2D, delivering the result of both processors. The new processor is driven by p2P, so, if the base functor represents a non-commutative monad, any effects of p2% will be observed before those of p1.*The +>->>q represents a pull-based composition of stream processors. that is partial on the left (supply) side, so that  p1 +>->> p2> represents a stream processor that forwards the output of p1 to p2, delivering the result of p2. and the remainder (unconsumed portion) of p1. The new processor is driven by p2P, so, if the base functor represents a non-commutative monad, any effects of p2% will be observed before those of p1.+The >>->+q represents a pull-based composition of stream processors that is partial on the right (demand) side, so that  p1 >->>+ p2> represents a stream processor that forwards the output of p1 to p2, delivering the result of p1. and the remainder (unproduced portion) of p2. The new processor is driven by p2P, so, if the base functor represents a non-commutative monad, any effects of p2% will be observed before those of p1.,An infix version of  flip fmap] with the same precedence and associativity as the stream processor composition operators ) and &`, indended for idiomatic processing of composition deliverables using expressions such as p >->> q >&> fst.-The qcompose f p q is precisely equivalent to p >->> q >&> uncurry fJ, but faster. A rewrite rule is included to replace applications of ) followed by , into -. !"#$%&'()*+,-  !"#$%&'()*+,-  !"#$%&)'(*+,- !"#$%&'()*+,-&'()*+,Simple stream processors*© 2015 Patryk Zadarnowski <pat@jantar.org>BSD3pat@jantar.org experimentalportableNoneFINZ.Simple processor result type./(An effect version of a simple processor.0)A consumer version of a simple processor.1)A producer version of a simple processor.2A simple processorÅ with a unit request type, an unspecified response type and a result type tailored towards reporting the terminating condition of an intermediate component in a composed processor stack .3A simple processor step> with a unit request type and an unspecified response type:4(\ ]\) Simple processor result value indicating successful processing of the entire input stream.5(\ (\ e)'W) Simple processor result value indicating unsuccessful processing of the input stream.6(]Q) Simple processor result value indicating premature termination of the consumer.7 Delivers an 4 result.8 Delivers an 5 result.9 Delivers an 6 result.:spfetchc represents a singleton simple stream processor that delivers the next input value received, or Nothing0 if the upstream processor has been depleted.;spemit yP represents a singleton stream processor that produces a single output value y, delivering either 4 if y1 was consumed by the downstream processor, or 6 otherwise.<y >:> pP represents a singleton stream processor that produces a single output value y% and continues with the processor p, deliverying 6 if y6 could not be consumed by the downstream processor.=p >>? q continues processing of p with q but only if p' completes successsfully by delivering 4, short-circuiting q if p fails with 6 or 5.>p >>! k is equivalent to p, with any failures in p+ supplied to the continuation processor k. Note that k is not executed if p completes successfully with 4> or is interrupted by the downstream processor, delivering 6.?sppure fE produces an infinite consumer/producer that uses a pure function f? to convert every input value into an output; equivalent to qpure id f (const ()).@7A simple identity processor, equivalent to 'sppure id'.A,A simple list flattening processor requests.B]A processor that delivers the entire input of the stream folded into a single value using ^.CsA processor that delivers the entire input of the stream folded into a single value using strict application of ^.D™A processor that delivers the entire input of the stream folded into a single value using the supplied left-associative function and initial value.E¯A processor that delivers the entire input of the stream folded into a single value using strict application of the supplied left-associative function and initial value.FšA processor that delivers the entire input of the stream folded into a single value using the supplied right-associative function and initial value.G°A processor that delivers the entire input of the stream folded into a single value using strict application of the supplied right-associative function and initial value.HdA processor that applies a monadic function to every input element and emits the resulting value.IGA processor that consumes every input elemnet using a monadic function.J/Produces every element of a foldable structure.K Evaluates an /·, i.e., a simple processor that is both detached and depleted and hence neither consumes nor produces any input, returning its delivered value. The base functor must be a monad../0123456789:;<=>?@ABCDEFGHIJK;  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJK3210/.456789:;<=>?@ABCDEFGHIJK./0123456789:;<=>?@ABCDEFGHIJK<=>_      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSQRTUVWUVXQRYZ[\Z[]Z[^Z[_`abcdefQRgQRhQRijquive_LGSIeo73vpf8i7e0vpe2keControl.Quiver.InternalControl.Quiver.TransControl.QuiverControl.Quiver.SPEffectConsumerProducerPConsumeProduceEncloseDeliverconsumeproduceenclosedeliverdecoupledepleteqliftqhoistqembed qRunErrorT qRunExceptT qRunMaybeTqRunRWST qRunLazyRWSTqRunStrictRWST qRunReaderT qRunStateTqRunLazyStateTqRunStrictStateT qRunWriterTqRunLazyWriterTqRunStrictWriterTfetchfetch_emitemit_qpureqidqconcat runEffect>>->+>>->>>->+>->>+>->>>->>+>&>qcomposeSPResultSEffect SConsumer SProducerSPSQ SPCompleteSPFailed SPIncomplete spcompletespfailed spincompletespfetchspemit>:>>>?>>!sppurespidspconcatspfoldspfold'spfoldlspfoldl'spfoldrspfoldr' sptraverse sptraverse_speverysprunbaseGHC.Base ApplicativeMonadtrans_FGrlaE81MpgDUE7QJ3IrHVControl.Monad.Trans.Classlift MonadTransFunctormmorp_LgkMDuSeTl6DWt57ZN8gyPControl.Monad.MorphhoistMFunctorembedMMonad $fMMonadP $fMFunctorP $fMonadIOP $fMonadTransP$fMonadP$fApplicativeP $fFunctorPJustNothingmappend