M8M      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmn o p q r s t u v w x y z { | } ~        !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLSafeD The empty type, denoting a 'C 'losed endA self-contained , ready to be run by  runSessions never request or respond.  Client a' a sends requests of type a'$ and receives responses of type a.s never respond.  Server b' b receives requests of type b'! and sends responses of type b.s never request. A & that consumes values flowing upstreams never request. A & that produces values flowing upstreams never respond. A   where everything flows upstreamA   that consumes valuess never respond. A   that produces valuess never request. A unidirectional Proxy. M   M Safe  s form a N/ instance when you rearrange the type variables 1A self-contained pipeline that is ready to be runA pipe that consumes valuesA pipe that produces valuesThe base type for pipesa1 - The type of input received from upstream pipesb3 - The type of output delivered to downstream pipesm - The base monadr - The type of the return valueWait for input from upstream./ blocks until input is available from upstream.Deliver output downstream.7 restores control back upstream and binds its value to .#Convert a pure function into a pipe 4pipe f = forever $ do x <- await yield (f x)Corresponds to (O)/(P) from Control.CategoryCorresponds to (Q) from Control.CategoryCorresponds to R from Control.CategoryRun the : monad transformer, converting it back into the base monad        88SafeOT!#A functor in the category of monads"Lift a monad morphism from m to n$ into a monad morphism from (t m) to (t n) #Lift the base monad raise = hoist lift !"#$%&'()*+!"#!"# !"#$%&'()*+SafeOT,The  (MonadIOP p)6 constraint is equivalent to the following constraint: D(forall a' a b' b m . (MonadIO m) => MonadIO (p a' a b' b m)) => ....The (MonadPlusP p)6 constraint is equivalent to the following constraint: D(forall a' a b' b m . (Monad m) => MonadPlus (p a' a b' b m)) => ...12Two extra Proxy categories of theoretical interest2f \>\ g replaces all 5s in g with f.3f />/ g replaces all 6s in f with g.4The core API for the pipes libraryYou should only use 5, 6, and (7)I only provide (8f) for theoretical symmetry, and the remaining methods just implement internal type class plumbing.55: input from upstream, passing an argument with the request request a' passes a'^ as a parameter to upstream that upstream may use to decide what response to return. 5/ binds the upstream's response of type a to its own return value. 66B with an output for downstream and bind downstream's next 5 respond b satisfies a downstream 5 by supplying the value b . 6 blocks until downstream 55s a new value and binds the argument of type b' from the next 5 as its return value. 7!Compose two proxies blocked on a 6., generating a new proxy blocked on a 63Begins from the downstream end and satisfies every 5 with a 6 8!Compose two proxies blocked on a 5., generating a new proxy blocked on a 51Begins from the upstream end and satisfies every 6 with a 5 99 is identical to S5, except with a more polymorphic constraint. :(:) is identical to (T6), except with a more polymorphic constraint. ;; is identical to U5, except with a more polymorphic constraint. << is identical to "5, except with a more polymorphic constraint. ==( forwards requests followed by responses !idT = request >=> respond >=> idT>>( forwards responses followed by requests %coidT = respond >=> request >=> coidT?!Compose two proxies blocked on a 6*, generating a new proxy blocked on a 63Begins from the downstream end and satisfies every 5 with a 6 @!Compose two proxies blocked on a 5*, generating a new proxy blocked on a 51Begins from the upstream end and satisfies every 6 with a 5=You don't need to use this. I include it only for symmetry. Af /</ g replaces all 5s in f with g.Bf \<\ g replaces all 6s in g with f.,-./0123456789:;<=>?@AB,-./01234567:89;<=>?@AB456789:;<=>?@123AB./0,- ,-./0123456789:;<=>?@AB283877:1?7A8B8SafeC$Uniform interface to lifting proxiesELift a 4 Kleisli arrow mapP = (lift .)CDECDECDECDESafeDOTF#A functor in the category of monadsGLift a proxy morphism from p to q$ into a proxy morphism from (t p) to (t q) HLift the base proxy raiseP = hoistP liftPFGHFGHFGHFGHNoneIA IH communicates with an upstream interface and a downstream interface.The type variables of )ProxyFast req_a' resp_a req_b' resp_b m r signify:req_a'1 - The request supplied to the upstream interfaceresp_a2 - The response provided by the upstream interfacereq_b'3 - The request supplied by the downstream interfaceresp_b4 - The response provided to the downstream interfacem  - The base monadr  - The final return value NRun a self-sufficient I9 Kleisli arrow, converting it back to the base monad ORun a self-sufficient IL Kleisli arrow, converting it back to a Kleisli arrow in the base monad PRun the Pipe8 monad transformer, converting it back to the base monadQ?The monad transformer laws are correct when viewed through the Q function: hobserve (lift (return r)) = observe (return r) observe (lift (m >>= f)) = observe (lift m >>= lift . f)This correctness comes at a moderate cost to performance, so use this function sparingly or else you would be better off using Control.Proxy.Core.Correct.OYou do not need to use this function if you use the safe API exported from  Control.Proxyf, which does not export any functions or constructors that can violate the monad transformer laws.WOnly satisfies laws modulo QIJKLMVWNOPQRSTUVWXYZ IMJKLNOPQ IJKLMNOPQIJKLMVWNOPQRSTUVWXYZSafeD[The Identity proxy transformer^Wrap a 'K'leisli arrow in [_Run an P 'K 'leisli arrow[\]^_`abcdefghijklm[\]^_[\]^_[\]^_`abcdefghijklm SafeDnA self-contained n that is ready to be runns never 5 nor 6. oWait for input from upstreamo0 blocks until input is available from upstream. pDeliver output downstreamp9 restores control back downstream and binds its value to o. q#Convert a pure function into a piperCorresponds to (<<<)/(X) from Control.CategorysCorresponds to (>>>) from Control.CategorytCorresponds to Y from Control.Categorynopqrstnopqrstopqrstnnopqrstr9 s9 SafeuThe base functor for the y typeyA yH communicates with an upstream interface and a downstream interface.The type variables of ,ProxyCorrect req_a' resp_a req_b' resp_b m r signify:req_a'1 - The request supplied to the upstream interfaceresp_a2 - The response provided by the upstream interfacereq_b'3 - The request supplied by the downstream interfaceresp_b4 - The response provided to the downstream interfacem  - The base monadr  - The final return value |Run a self-sufficient y9 Kleisli arrow, converting it back to the base monad }Run a self-sufficient yL Kleisli arrow, converting it back to a Kleisli arrow in the base monad ~Run the Pipe8 monad transformer, converting it back to the base monaduvwxyz{|}~ uxvwyz{|}~ yz{uvwx|}~uvwxyz{|}~ SafeDThe Z proxy transformerRun an  'K!'leisi arrow, returning either a [ or \#Abort the computation and return a [ result Synonym for S Synonym for  Resume from an aborted operation with the arguments flippedOriginal computationHandlerHandled computationHandlerOriginal computationHandled computation  SafeDThe ] proxy transformerRun a  'K''leisli arrow, returning the result or ^A synonym for _A synonym for S SafeDThe Reader proxy transformerRun a ' computation, supplying the environmentRun a  'K('leisli arrow, supplying the environment>Modify a computation's environment (a more general version of )Get the environment!Get a function of the environment8Modify a computation's environment (a specialization of ) SafeD The State proxy transformerRun a 2 computation, producing the final result and stateRun a  'K3'leisli arrow, procuding the final result and state Evaluate a ) computation, but discard the final state Evaluate a  'K*'leisli arrow, but discard the final state Evaluate a * computation, but discard the final result Evaluate a  'K+'leisli arrow, but discard the final resultGet the current stateSet the current state)Modify the current state using a function)Get the state filtered through a function SafeD The strict Writer proxy transformerRun a 3 computation, producing the final result and monoidRun a  'K4'leisli arrow, producing the final result and monoid Evaluate a * computation, but discard the final result Evaluate a  'K+'leisli arrow, but discard the final resultAdd a value to the monoid)Modify the result of a writer computation Safe<(mapD f) applies f to all values going 'D 'ownstream. 3mapD f1 >-> mapD f2 = mapD (f2 . f1) mapD id = idT(mapU g) applies g to all values going 'U 'pstream. 3mapU g1 >-> mapU g2 = mapU (g1 . g2) mapU id = idT (mapB f g) applies f$ to all values going downstream and g" to all values going upstream.Mnemonic: map 'B 'idirectional FmapB f1 g1 >-> mapB f2 g2 = mapB (f2 . f1) (g1 . g2) mapB id id = idT (mapMD f) applies the monadic function f to all values going downstream =mapMD f1 >-> mapMD f2 = mapMD (f1 >=> f2) mapMD return = idT (mapMU g) applies the monadic function g to all values going upstream =mapMU g1 >-> mapMU g2 = mapMU (g2 >=> g1) mapMU return = idT (mapMB f g) applies the monadic function f= to all values going downstream and the monadic function g to all values going upstream. VmapMB f1 g1 >-> mapMB f2 g2 = mapMB (f1 >=> f2) (g2 >=> g1) mapMB return return = idT(useD f) executes the monadic function f on all values flowing 'D 'ownstream MuseD f1 >-> useD f2 = useD (\a -> f1 a >> f2 a) useD (\_ -> return ()) = idT(useU g) executes the monadic function g on all values flowing 'U'pstream PuseU g1 >-> useU g2 = useU (\a' -> g2 a' >> g1 a') useU (\_ -> return ()) = idT (useB f g) executes the monadic function f? on all values flowing downstream and the monadic function g on all values flowing upstream }useB f1 g1 >-> useB f2 g2 = useB (\a -> f1 a >> f2 a) (\a' -> g2 a' >> g1 a') useB (\_ -> return ()) (\_ -> return ()) = idT (execD md) executes md. every time values flow downstream through it. EexecD md1 >-> execD md2 = execD (md1 >> md2) execD (return ()) = idT (execU mu) executes mu, every time values flow upstream through it. EexecU mu1 >-> execU mu2 = execU (mu2 >> mu1) execU (return ()) = idT (execB md mu) executes mu> every time values flow upstream through it, and executes md. every time values flow downstream through it. ZexecB md1 mu1 >-> execB md2 mu2 = execB (md1 >> md2) (mu2 >> mu1) execB (return ()) = idT (takeB n) allows n/ upstream/downstream roundtrips to pass through PtakeB n1 >=> takeB n2 = takeB (n1 + n2) -- n1 >= 0 && n2 >= 0 takeB 0 = return is  with a ()' return value, convenient for composing(takeWhileD p)L allows values to pass downstream so long as they satisfy the predicate p. -- Using the "All" monoid over functions: mempty = \_ -> True (p1 <> p2) a = p1 a && p2 a takeWhileD p1 >-> takeWhileD p2 = takeWhileD (p1 <> p2) takeWhileD mempty = idT(takeWhileU p)J allows values to pass upstream so long as they satisfy the predicate p. PtakeWhileU p1 >-> takeWhileU p2 = takeWhileU (p1 <> p2) takeWhileD mempty = idT (dropD n) discards n values going downstream MdropD n1 >-> dropD n2 = dropD (n1 + n2) -- n2 >= 0 && n2 >= 0 dropD 0 = idT  (dropU n) discards n values going upstream MdropU n1 >-> dropU n2 = dropU (n1 + n2) -- n2 >= 0 && n2 >= 0 dropU 0 = idT (dropWhileD p)G discards values going downstream until one violates the predicate p. -- Using the "Any" monoid over functions: mempty = \_ -> False (p1 <> p2) a = p1 a || p2 a dropWhileD p1 >-> dropWhileD p2 = dropWhileD (p1 <> p2) dropWhileD mempty = idT (dropWhileU p)E discards values going upstream until one violates the predicate p. PdropWhileU p1 >-> dropWhileU p2 = dropWhileU (p1 <> p2) dropWhileU mempty = idT  (filterD p)A discards values going downstream if they fail the predicate p -- Using the "All" monoid over functions: mempty = \_ -> True (p1 <> p2) a = p1 a && p2 a filterD p1 >-> filterD p2 = filterD (p1 <> p2) filterD mempty = idT  (filterU p); discards values going upstream if they fail the predicate p DfilterU p1 >-> filterU p2 = filterU (p1 <> p2) filterU mempty = idTConvert a list into a  KfromListS xs >=> fromListS ys = fromListS (xs ++ ys) fromListS [] = returnConvert a list into a  KfromListC xs >=> fromListC ys = fromListC (xs ++ ys) fromListC [] = return version of ` version of ` version of a version of aFold values flowing 'D 'ownstream 8foldD f >-> foldD g = foldD (f <> g) foldD mempty = idTFold values flowing 'U'pstream 8foldU f >-> foldU g = foldU (g <> f) foldU mempty = idTFold that returns whether b values flowing 'D%'ownstream satisfy the predicate Fold that returns whether b values flowing 'U#'pstream satisfy the predicate Fold that returns whether b values flowing 'D$'ownstream satisfy the predicate8 terminates on the first value that fails the predicate Fold that returns whether b values flowing 'U"'pstream satisfy the predicate8 terminates on the first value that fails the predicate Fold that returns whether c value flowing 'D''ownstream satisfies the predicate Fold that returns whether c value flowing 'U%'pstream satisfies the predicate Fold that returns whether c value flowing 'D&'ownstream satisfies the predicate< terminates on the first value that satisfies the predicate Fold that returns whether c value flowing 'U$'pstream satisfies the predicate< terminates on the first value that satisfies the predicate  Compute the d of all values that flow 'D 'ownstream Compute the d of all values that flow 'U'pstream  Compute the e of all values that flow 'D 'ownstream! Compute the e of all values that flow 'U'pstream"Count how many values flow 'D 'ownstream#Count how many values flow 'U'pstream$ Retrieve the first value going 'D 'ownstream% Retrieve the first value going 'D 'ownstream%+ terminates on the first value it receives & Retrieve the first value going 'U'pstream' Retrieve the first value going 'U'pstream'+ terminates on the first value it receives (Retrieve the last value going 'D 'ownstream)Retrieve the last value going 'U'pstream*Fold the values flowing 'D'ownstream into a list+Fold the values flowing 'U'pstream into a list,Fold equivalent to f.To see why, consider this isomorphic type for f: 'foldr :: (a -> b -> b) -> [a] -> Endo b-Fold equivalent to f.Left strict fold over 'D'ownstream values/Left strict fold over 'U'pstream values0Zip values flowing downstream1=Interleave values flowing downstream using simple alternation2Compose 27 with a closed upstream end to create a polymorphic end3Compose 39 with a closed downstream end to create a polymorphic end<      !"#$%&'()*+,-./0123^ghijbklcmndopeqrstuvwxyz{|}~      !"#$%&'()*+,-./0123<      !"#$%&'()*+,-./0123<      !"#$%&'()*+,-./0123SafeOT4 Compose a 'K!'leisli arrow with itself foreverUse 49 to abstract away the following common recursion pattern: -p a = do ... a' <- respond b p a'Using 4, you can instead write: -p = foreverK $ \a -> do ... respond b5 Repeat a 'K'leisli arrow multiple times6#Convenience function equivalent to (lift .) <liftK f >=> liftK g = liftK (f >=> g) liftK return = return7#Convenience function equivalent to  (hoist f .) FhoistK f p1 >-> hoistK f p2 = hoistK f (p1 >-> p2) hoistK f idT = idT LhoistK f p1 >=> hoistK f p2 = hoistK f (p1 >=> p2) hoistK f return = return 4hoistK f . hoistK g = hoistK (f . g) hoistK id = id8#Convenience function equivalent to (hoist lift .) >raiseK p1 >-> raiseK p2 = raiseK (p1 >-> p2) raiseK idT = idT DraiseK p1 >=> raiseK p2 = raiseK (p1 >=> p2) raiseK return = return45678456784567845678Safe9A  that sends lines from stdin downstream:A  that sends lines from stdin upstream; input from stdin one line at a time and send 'D 'ownstream< input from stdin one line at a time and send 'U'pstream=#s all values flowing through it to stdoutPrefixes upstream values with "U: " and downstream values with "D: ">s all values flowing 'D'ownstream to stdout?s all values flowing 'U 'pstream to stdout@#s all values flowing through it to stdoutPrefixes upstream values with "U: " and downstream values with "D: "As all values flowing 'D'ownstream to stdoutBs all values flowing 'U 'pstream to stdoutCConvert 'stdin'/'stdout' into a line-based DConvert 'stdin'/'stdout' into a line-based EA * that sends lines from a handle downstreamFA  that sends lines from a Handle upstreamG%s all values flowing through it to a HandlePrefixes upstream values with "U: " and downstream values with "D: "Hs all values flowing 'D'ownstream to a HandleIs all values flowing 'U'pstream to a HandleJ%s all values flowing through it to a HandlePrefixes upstream values with "U: " and downstream values with "D: "Ks all values flowing 'D'ownstream to a HandleLs all values flowing 'U'pstream to a Handle9:;<=>?@ABCDEFGHIJKL9:;<=>?@ABCDEFGHIJKL9:;<=>?@ABCDEFGHIJKL9:;<=>?@ABCDEFGHIJKLSafewghijbklcmndopeqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLSafeghijbklcmndopeqrstuvwxyz{|}~U !",-./01234567:89;<=>?@ABCDE[\]^_      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLNoneghijbklcmndopeqrstuvwxyz{|}~U !",-./01234567:89;<=>?@ABCDEINOPQ[\]^_      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLNone !!"# $%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^&'_`.abcdefghijkklmnopqrstuvwxyz{| # ( ) * + , - } ] ^ ' ~ G  _ ` .             !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKIJLIJMIJNIJOIPQIPRSTUVWIPMIPOIXYIXZIX[IP\IP]IP^I_`I_aIbcIbdIbeIbfIghIPiIbjIbjIbkIbcIblIbdIbmIbeIbnIbfIboIbpIbpIbqIbrIbrIbsStStuStvStwStxSySySyzSy{Sy|Sy}Sy~IIIIIIST"pipes-3.0.0-GyiVUIOb8oZFpjdZZtoStpControl.Proxy.Synonym Control.PipeControl.MFunctorControl.Proxy.ClassControl.Proxy.TransControl.PFunctorControl.Proxy.Core.FastControl.Proxy.Trans.IdentityControl.Proxy.PipeControl.Proxy.Core.CorrectControl.Proxy.Trans.EitherControl.Proxy.Trans.MaybeControl.Proxy.Trans.ReaderControl.Proxy.Trans.StateControl.Proxy.Trans.WriterControl.Proxy.Prelude.BaseControl.Proxy.Prelude.KleisliControl.Proxy.Prelude.IOControl.Proxy.PreludeControl.Proxy.Core Control.ProxyControl.Proxy.TutorialCSessionClientServer CoConsumer CoProducerCoPipeConsumerProducerPipePipeCunPipeCPipelineAwaitYieldMPureawaityieldpipe<+<>+>idPrunPipe$fCategoryTYPEPipeC$fMonadTransPipe $fMonadPipe$fApplicativePipe $fFunctorPipeMFunctorhoistraise$fMFunctorWriterT$fMFunctorWriterT0$fMFunctorStateT$fMFunctorStateT0$fMFunctorRWST$fMFunctorReaderT$fMFunctorMaybeT$fMFunctorIdentityTMonadIOPliftIO_P MonadPlusPmzero_Pmplus_PInteract\>\/>/Proxyrequestrespond>->>~>return_P?>=lift_Phoist_PidTcoidT<-<<~</>>idGHC.Basereturn>>=transformers-0.5.2.0Control.Monad.Trans.Classlift_bind_lift Data.EitherEitherLeftRightMaybeNothingmzeroGHC.EnumenumFrom enumFromTo Data.MonoidAllAnySumProduct Data.FoldablefoldrMonoidEndoappEndogetAllgetAnygetSum getProductFirstgetFirstLastgetLast!Control.Monad.Trans.Writer.Strict execWriterT runWriterWriterT runWriterT Control.Monad.Trans.State.Strict execStateT execStaterunStateStateT runStateT Text.Readread System.IOprintputStrLn Control.Monadforever<=<>=> MonadTrans