h*|ta      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz { | } ~                                                                                               1.3 Safe-Inferred'1 Safe-Inferred'1: automatonInternal state of many and some> automaton Internal state of the result of  Alternative constructionsB automatonA strict tuple type798:<;=>A@?BCDBC>A@?:<;=798D Safe-Inferred'19E automatonA state transformer with H+ instead of a standard tuple as its result.H automaton-A tuple that is strict in its first argument.This type is used in streams and automata to encode the result of a state transition. The new state should always be strict to avoid space leaks.L automaton#Apply a function to the state of a H.M automaton Analogous to  Applicative's . EGFHKJILM HKJILMEGF Safe-Inferred')*16$R automaton&Effectful streams in initial encoding.'A stream consists of an internal state s>, and a step function. This step can make use of an effect in m (which is often a monad), alter the state, and return a result value. Its semantics is continuously outputting values of type b#, while performing side effects in m.An initial encoding was chosen instead of the final encoding known from e.g. list-transformer, dunai, machines,  streaming, ..., because the initial encoding is much more amenable to compiler optimizations than the final encoding, which is:  data StreamFinalT m b = StreamFinalT (m (b, StreamFinalT m b)) When two streams are composed, GHC can often optimize the combined step function, resulting in a faster streams than what the final encoding can ever achieve, because the final encoding has to step through every continuation. Put differently, the compiler can perform static analysis on the state types of initially encoded state machines, while the final encoding knows its state only at runtime.This performance gain comes at a peculiar cost: Recursive definitions of2 streams are not possible, e.g. an equation like:  fixA stream = stream  * fixA stream  This is impossible since the stream under definition itself appears in the definition body, and thus the internal  state type would be recursively defined, which GHC doesn't allow: Type level recursion is not supported in existential types. An stream defined thusly will typically hang and/or leak memory, trying to build up an infinite type at runtime.It is nevertheless possible to define streams recursively, but one needs to first identify the recursive definition of its  state type$. Then for the greatest generality, b and c can be used, and some special cases are covered by functions such as d,  ,  and .T automaton The internal state of the streamU automatonStepping a stream by one tick means: 1. performing a side effect in m# 2. updating the internal state s" 3. outputting a value of type aV automatonInitialise with an internal state, update the state and produce output without side effects.W automatonLike V, but output the current state.X automatonConstantly perform the same effect, without remembering a state.Y automatonHoist a stream along a monad morphism, by applying said morphism to the step function. This is like mmorph's , but it doesn't require a  constraint on m2.Z automatonPerform one step of a stream, resulting in an updated stream and an output value.[ automaton!Run a stream with trivial output.If the output of a stream does not contain information, all of its meaning is in its effects. This function runs the stream indefinitely. Since it will never return with a value, this function also has no output (its output is void). The only way it can return is if m+ includes some effect of termination, e.g.  or  could terminate with a  or  value, or  can raise an exception.\ automaton>Run a stream, collecting the outputs in a lazy, infinite list.] automatonChange the output type and effect of a stream without changing its state type.^ automaton=Buffer the output of a stream, returning one value at a time.This function lets a stream control the speed at which it produces data, since it can decide to produce any amount of output at every step._ automatonStreams with exceptions are  in the exception type.Run the first stream until it throws a function as an exception, then run the second one. If the second one ever throws an exception, apply the function thrown by the first one to it.` automatonWhenever an exception occurs, output it and retry on the next step.a automatonRun the first stream until it throws an exception. If the exception is #, throw it immediately. If it is , run the second stream until it throws a function, which is then applied to the first exception.b automatonRecursively define a stream from a recursive definition of the state, and of the step function.If you want to define a stream recursively, this is not possible directly. For example, consider this definition: 1 loops :: Monad m => StreamT m [Int] loops = (:)  $ unfold_ 0 (+ 1)  * loops  The defined value loops contains itself in its definition. This means that the internal state type of loops must itself be recursively defined. But GHC cannot do this automatically, because type level and value level are separate. Instead, we need to spell out the type level recursion explicitly with a type constructor, over which we will take the fixpoint.In this example, we can figure out from the definitions that: 1. W 0 (+ 1) has 0 :: Int as state 2. (:) does not change the state 3. ! takes the product of both statesSo the internal state s of loops must satisfy the equation  s = (Int, s). If the recursion is written as above, it tries to compute the infinite tuple (Int, (Int, (Int, ...))), which hangs. Instead, we need to define a type operator over which we take the fixpoint: -- You need to write this: data Loops x = Loops Int x -- The library supplies: data Fix f = Fix f (Fix f) type LoopsState = Fix Loops We can then use b' to define the recursive definition of loops>. For this, we have to to tediously inline the definitions of W, (:), and , until we arrive at an explicit recursive definition of the state and the step function of loops-, separately. These are the two arguments of b. loops :: Monad m => StreamT m [Int] loops = fixStream (Loops 0) $ fixStep (Loops n fixState) -> do Result s' a <- fixStep fixState return $ Result (Loops (n + 1) s') a c automatonA generalisation of b= where the step definition is allowed to depend on the state.d automatonThe solution to the equation 'fixA stream = stream  * d stream.Such a fix point operator needs to be used instead of the above direct definition because recursive definitions of streams loop at runtime due to the initial encoding of the state.i automaton just performs  in the underlying monad m. s1  s2 starts in an undecided state, and explores the possibilities of continuing in s1 or s2+ on the first tick, using the underlying m.m automaton! forever returns the same value, ! steps two streams synchronously.b automaton4The recursive definition of the state of the stream. automaton>> automaton2parallely :: Automaton m (a, b) (b, c) parallely = automaton1 *** automaton2 @ In sequential composition, the output of the first automaton is passed as input to the second one. In parallel composition, both automata receive input simulataneously and process it independently. Through the  type class, you can use  to create an automaton from a pure function, and more generally use the arrow syntax extension to define automata. automaton Create an ' from a state and a pure step function. automaton Create an - from a state and an effectful step function. automatonConsume an input and produce output effectfully, without keeping internal state automaton:Produce output effectfully, without keeping internal state automaton2Apply an arbitrary monad morphism to an automaton. automaton0Lift the monad of an automaton to a transformer. automatonExtend the internal state and feed back part of the output to the next input.This is one of the fundamental ways to incorporate recursive dataflow in automata. Given an automaton which consumes an additional input and produces an additional output, the state of the automaton is extended by a further value. This value is used as the additional input, and the resulting additional output is stored in the internal state for the next step. automatonRun one step of an automaton.This consumes an input value, performs a side effect, and returns an updated automaton together with an output value. automaton AutomatonExcept a b m e2?example :: AutomatonExcept a b m e2 example = automaton >>= f @Here,  automaton produces output values of type b until an exception e1 occurs. The function f is called on the exception value and produces a continuation automaton which is then executed (until it possibly throws an exception e2 itself).The generality of the monad interface comes at a cost, though. In order to achieve higher performance, you should use the  interface sparingly. Whenever you can express the same control flow using , , , or just the  operator, you should do this. The encoding of the internal state type will be much more efficiently optimized.-The reason for this is that in an expression ma >>= f, the type of f is e1 -> AutomatonExcept a b m e2&, which implies that the state of the  produced isn't known at compile time, and thus GHC cannot optimize the automaton. But often the full expressiveness of  isn't necessary, and in these cases, a much faster automaton is produced by using ,  and ."Note: By "exceptions", we mean an  transformer layer, not  exceptions. automatonThrow the exception e$ whenever the function evaluates to . automaton'Throws the exception when the input is . Variant of  for Kleisli arrows. automaton&Throw the exception when the input is . automaton Variant of ,, where the exception may change every tick. automatonWhen the input is Just e, throw the exception e.This does not output any data since it terminates on the first nontrivial input. automaton)Immediately throw the incoming exception.This is useful to combine with  ArrowChoice , e.g. with if and case expressions in Arrow syntax. automaton&Immediately throw the given exception. automatonDo not throw an exception. automaton Converts an  in  to an  in . Whenever  is thrown, throw () instead. automatonCatch an exception in an .0As soon as an exception occurs, switch to a new 6, the exception handler, based on the exception value.For exception catching where the handler can throw further exceptions, see  further below. automaton.Similar to Yampa's delayed switching. Loses a b in case of an exception. automaton Escape an 6 layer by outputting the exception whenever it occurs.If an exception occurs, the current state is is tested again on the next input. automaton Embed an  value inside the .Whenever the input value is an ordinary value, it is passed on. If it is an exception, it is raised. automatonIn case an exception occurs in the first argument, replace the exception by the second component of the tuple. automaton Execute an  in  until it raises an exception.-Typically used to enter the monad context of . automaton4Immediately throw the current input as an exception.Useful inside  if you don't want to advance a further step in execution, but first see what the current input is before continuing. automatonIf no exception can occur, the  can be executed without the  layer.Used to exit the $ context, often in combination with : automaton = safely $ do e <- try someAutomaton once $ input -> putStrLn $ "Whoops, something happened when receiving input " ++ show input ++ ": " ++ show e ++ ", but I'll continue now." safe fallbackAutomaton  automatonAn  without an  layer never throws an exception, and can thus have an arbitrary exception type.)In particular, the exception type can be 0, so it can be used as the last statement in an  do -block. See  for an example. automaton Inside the  monad, execute an action of the wrapped monad. This passes the last input value to the action, but doesn't advance a tick. automaton Variant of  without input. automatonAdvances a single tick with the given Kleisli arrow, and then throws an exception. automaton=Advances a single tick outputting the value, and then throws (). automatonConverts a list to an >, which outputs an element of the list at each step, throwing () when the list ends. automaton Extract an  from a monadic action.'Runs a monadic action that produces an  on the first step, and then runs result for all further inputs (including the first one). automatons an  until it throws an exception. automatons an  until it returns . automatonRun the first / until the second value in the output tuple is Just c, then start the second automaton, discarding the current output b.This is analogous to Yampa's  https://hackage.haskell.org/package/Yampa/docs/FRP-Yampa-Switches.html#v:switchswitch, with  instead of Event. automatonRun the first / until the second value in the output tuple is Just c, then start the second automaton one step later (after the current b has been output).Analog to Yampa's  https://hackage.haskell.org/package/Yampa/docs/FRP-Yampa-Switches.html#v:dSwitchdswitch, with  instead of Event.$$ Safe-Inferred'1s  automaton Throw the exception immediately. automatonThrow the exception when the condition becomes true on the input. automaton Exit when the incoming value is . automatonJust a is passed along,  causes the whole  to exit. automatonEmbed a  value in the  layer. Identical to . automaton6Run the first automaton until the second one produces  from the output of the first. automaton&When an exception occurs in the first  automaton , the second  automaton is executed from there. automatonConvert exceptions into !, discarding the exception value. automatonConverts a list to an  in >, which outputs an element of the list at each step, throwing  when the list ends. automaton Remove the  layer by outputting  when the exception occurs.9The current state is then tested again on the next input. automaton reactimates an  in the  monad until it throws . automatonRun an  fed from a list, discarding results. Useful when one needs to combine effects and streams (i.e., for testing purposes). ! ! Safe-Inferred'1tI automatonAutomata in final encoding. !"#$%&'()*+*+*,*-*.*/*0*1*23456789:;<=>?@ABCDEFGH*=*>*?*@*BIIJKLMNOPQRSSTUUVWWXYZ[\]^_``Cabcdefghijklmnopqrstuvwxyz{{|}~d     e    g d  } ~  k j l               }            b   d     g                                               Aka{{|}~HDECFG:<;9$automaton-1.3-EyOJ8jVvIL4FjUWClbenXgData.Automaton.Trans.ExceptData.Automaton.Trans.MaybeData.Automaton.Trans.RWSData.Automaton.Trans.WriterData.Stream.InternalData.Stream.Result Data.StreamData.Stream.FinalData.Stream.OptimizedData.Stream.ExceptData.AutomatonData.Automaton.Trans.StateData.Automaton.Trans.ReaderData.Automaton.Trans.RandomData.Automaton.Final automaton$Data.Automaton.Trans.Except.Internal parallelyData.Stream.Final.ExceptAutomatonExceptconcatStransformers-0.6.1.0Control.Monad.Trans.ExceptExceptTControl.Monad.Trans.MaybeMaybeT runExceptTControl.Monad.Trans.RWS.StrictRWSTrunRWSTRWSrwsrunRWSevalRWSexecRWSmapRWSwithRWSevalRWSTexecRWSTmapRWSTwithRWST!Control.Monad.Trans.Writer.StrictWriterT runWriterTWriter runWriter execWriter mapWriter execWriterT mapWriterTthrowE runMaybeT mapMaybeT hoistMaybemaybeToExceptTexceptToMaybeTreaderasklocalaskswritertelllistenlistenspasscensorstategetputmodifygets liftCallCC'FixgetFixMany NotStartedOngoingFinished Alternatively UndecidedDecideLDecideR JointStatefixState ResultStateTgetResultStateTResult resultStateoutputmapResultStateapResult$fBifunctorResult$fApplicativeResultStateT$fFunctorResultStateT$fFunctorResultStreamTstepunfoldunfold_constMhoist' stepStream reactimate streamToList withStreamT applyExceptexceptS selectExcept fixStream fixStream'fixA$fAlignStreamT$fSemialignStreamT$fSelectiveStreamT$fMFunctorTYPEStreamT$fAlternativeStreamT$fVectorSpaceStreamTStreamT$fFloatingStreamT$fFractionalStreamT$fApplicativeStreamT$fFunctorStreamT $fNumStreamTFinalgetFinaltoFinal fromFinal$fAlternativeFinal$fApplicativeFinal$fFunctorFinal$fMFunctorTYPEFinalOptimizedStreamTStateful Stateless toStreamTmapOptimizedStreamT withOptimizedhandleOptimizedstepOptimizedStream$fMFunctorTYPEOptimizedStreamT$fAlignOptimizedStreamT$fSemialignOptimizedStreamT$fSelectiveOptimizedStreamT$fAlternativeOptimizedStreamT-$fVectorSpaceOptimizedStreamTOptimizedStreamT$fFloatingOptimizedStreamT$fFractionalOptimizedStreamT$fApplicativeOptimizedStreamT$fFunctorOptimizedStreamT$fNumOptimizedStreamT StreamExcept FinalExcept InitialExceptrunStreamExceptsafely$fMFunctorTYPEStreamExcept$fMonadTransStreamExcept$fMonadStreamExcept$fSelectiveStreamExcept$fApplicativeStreamExcept$fFunctorStreamExcept Automaton getAutomatonunfoldMarrMhoistSliftSfeedback stepAutomatonembed withAutomaton mapMaybeS traverseS traverseS_handleAutomaton_handleAutomatonwithSideEffectaccumulateWith mappendFromdelayprependmappendSsumFromsumSsumNcountlastS$fTraversingAutomaton$fStrongAutomaton$fChoiceAutomaton$fProfunctorAutomaton$fArrowPlusAutomaton$fArrowZeroAutomaton$fArrowLoopAutomaton$fArrowChoiceAutomaton$fArrowAutomaton$fCategoryTYPEAutomaton$fAlignAutomaton$fSemialignAutomaton$fVectorSpaceAutomatonAutomaton$fFunctorAutomaton$fApplicativeAutomaton$fAlternativeAutomaton$fSelectiveAutomaton$fNumAutomaton$fFractionalAutomaton$fFloatingAutomatonwriterS runWriterSstateS runStateS runStateS_ runStateS__readerS runReaderS runReaderS_ getRandomS getRandomsS getRandomRS getRandomRS_ getRandomsRS getRandomsRS_runRandS evalRandSrwsSrunRWSSgetAutomatonExcept throwOnCond throwOnCondMthrowOnthrowOn' throwMaybethrowSthrowmaybeToExceptScatchSuntilE inExceptTtaggedrunAutomatonExcepttry currentInputsafeonceonce_step_listToAutomatonExceptperformOnFirstSamplereactimateExcept reactimateBswitchdSwitch$fMFunctorTYPEAutomatonExcept$fMonadTransAutomatonExcept$fFunctorAutomatonExcept$fApplicativeAutomatonExcept$fSelectiveAutomatonExcept$fMonadAutomatonExceptexitexitWhenexitIf maybeExitinMaybeT untilMaybe catchMaybeexceptToMaybeS listToMaybeS runMaybeSreactimateMaybeembed_ $fArrowFinal$fCategoryTYPEFinal commuteReadercommuteReaderBackbaseGHC.Base<*>manysome#mmorph-1.2.0-HvKVm3PILerCzVOEB86i7sControl.Monad.MorphhoistMonad GHC.MaybeMaybe Data.EitherEitherNothingLeftghc-prim GHC.TypesIO ApplicativeRightempty<|>pure handleExceptT(selective-0.7.0.1-FXtE8pgkiPR4pGu9PtTi7LControl.Selective SelectiveFunctor>>=returnControl.CategoryCategory Control.ArrowArrow'profunctors-5.6.2-2kabKJBsc76aBEOjJ4aUXData.Profunctor.Unsafe ProfunctorarrJustControl.Monad.Trans.ReaderReaderTmappendmemptyloop Control.Monad.Trans.State.StrictStateT runStateTState liftCallCC liftCatch liftListenliftPassrunState execState evalStatemapState withState evalStateT execStateT mapStateT withStateTmodify'modifyM runReaderTReader runReader mapReader withReader mapReaderT withReaderT&MonadRandom-0.6-AklQZKoehI4GaEzNpzqsf6Control.Monad.Trans.Random.LazyRandT>>TrueVoid