s@eF      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`a b c d e f g h i j k l m n o p q r s t u v w x y z { |}~ Safe&',-;<=>?FQSTVLeft-edge deconstructionMNon-empty tree. Deconstruction operations make it more and more left-leaningThere is no tempty: use (tsingleton return), which works just the same. The names are chosen for compatibility with FastTCQueuesnoc: clearly constant-timeappend: clearly constant-time$Process the Left-edge deconstruction Trustworthy&'+,-;<=>?AFQSTV%3This class is used for emulating monad transformersRUsing overlapping instances here is OK since this class is private to this module!Find an index of an element in a list The element must exist This is essentially a compile-time computation. Using overlapping instances here is OK since this class is private to this module+A useful operator for reducing boilerplate. 9f :: [Reader Int, Writer String] <:: r => a -> Eff r b  is equal to If :: (Member (Reader Int) r, Member (Writer String) r) => a -> Eff r b /The data constructors of Union are not exportedStrong Sum (Existential with the evidence) is an open union t is can be a GADT and hence not necessarily a Functor. Int is the index of t in the list r; that is, the index of t in the universe r wExplicit type-level equality condition is a dirty hack to eliminate the type annotation in the trivial case, such as run (runReader () get).2There is no ambiguity when finding instances for Member t (a ': b ': r)(, which the second instance is selected.-The only case we have to concerned about is  Member t '[s]. But, in this case, values of definition is the same (if present), and the first one is chosen according to GHC User Manual, since the latter one is incoherent. This is the optimal choice.  Trustworthy&',-;<=>?FNQSTVO6%Lifting: emulating monad transformers\The Eff monad (not a transformer!). It is a fairly standard coroutine monad where the type rC is the type of effects that can be handled, and the missing type a (from the type application) is the type of value that is returned. It is NOT a Free monad! There are no Functor constraints.The two constructors denote the status of a coroutine (client): done with the value of type a, or sending a request of type Union r with the continuation Arrs r b a. Expressed another way: an  can either be a value (i.e.,  case), or an effect of type  r producing another  (i.e.,  case). The result is that an + can produce an arbitrarily long chain of  r' effects, terminated with a pure value. Potentially, inline Union into EAn effectful function from a to bi that is a composition of one or more effectful functions. The paremeter r describes the overall effect.lThe composition members are accumulated in a type-aligned queue. Using a newtype here enables us to define Category and Arrow instances.QEffectful arrow type: a function from a to b that also does effects denoted by rCconvert single effectful arrow into composable type. i.e., convert  to OApplication to the `generalized effectful function' Arrs r b w, i.e., convert  to Syntactic sugar for Lift a function to an arrowThe identity arrowArrow compositionCommon pattern: append  to :Compose effectful arrows (and possibly change the effect!):Compose effectful arrows (and possibly change the effect!)MSend a request and wait for a reply (resulting in an effectful computation).EThe initial case, no effects. Get the result from a pure computation.]The type of run ensures that all effects must be handled: only pure computations may be run.RA convenient pattern: given a request (open union), either handle it or relay it.Parameterized handle_relayWAdd something like Control.Exception.catches? It could be useful for control with cut.sIntercept the request and possibly reply to it, but leave it unhandled (that's why we use the same r all throuout)Embeds a less-constrained 2 into a more-constrained one. Analogous to MTL's .4We make the Lift layer to be unique, using SetMember_The handler of Lift requests. It is meant to be terminal: we only allow a single Lifted Monad.bEff is still a monad and a functor (and Applicative) (despite the lack of the Functor constraint)As the name suggests,  also has an Arrow instance.- can be composed and have a natural identity.Safe&',-;<=>?FQSTVc The Writer monadIn MTL's Writer monad, the told value must have a |Monoid| type. Our writer has no such constraints. If we write a |Writer|-like interpreter to accumulate the told values in a monoid, it will have the |Monoid w| constraint thenWrite a new value.#Transform the state being produced.jHandle Writer requests, using a user-provided function to accumulate values, hence no Monoid constraints.:Handle Writer requests, using a List to accumulate values.EHandle Writer requests, using a Monoid instance to accumulate values.:Handle Writer requests by taking the first value provided.6Handle Writer requests by overwriting previous values.zHandle Writer requests, using a user-provided function to accumulate values and returning the final accumulated values. hHandle Writer requests, using a List to accumulate values and returning the final accumulated values.!sHandle Writer requests, using a Monoid instance to accumulate values and returning the final accumulated values."lHandle Writer requests by taking the first value provided and and returning the final accumulated values.#dHandle Writer requests by overwriting previous values and returning the final accumulated values. !"#"# !Safe&',-;<=>?FQSTVw %The Writer monadIn MTL's Writer monad, the told value must have a |Monoid| type. Our writer has no such constraints. If we write a |Writer|-like interpreter to accumulate the told values in a monoid, it will have the |Monoid w| constraint then'Write a new value.(#Transform the state being produced.)jHandle Writer requests, using a user-provided function to accumulate values, hence no Monoid constraints.*:Handle Writer requests, using a List to accumulate values.+EHandle Writer requests, using a Monoid instance to accumulate values.,:Handle Writer requests by taking the first value provided.-6Handle Writer requests by overwriting previous values..zHandle Writer requests, using a user-provided function to accumulate values and returning the final accumulated values./hHandle Writer requests, using a List to accumulate values and returning the final accumulated values.0sHandle Writer requests, using a Monoid instance to accumulate values and returning the final accumulated values.1lHandle Writer requests by taking the first value provided and and returning the final accumulated values.2dHandle Writer requests by overwriting previous values and returning the final accumulated values.%&'()*+,-./012%&'(),-*+.12/0%&Safe&',-;<=>?FQSTV[4The Reader monadThe request for a value of type e from the current environment This can be expressed as a GADT because the type of values returned in response to a (Reader e a) request is not any a; we expect in reply the value of type eM, the value from the environment. So, the return type is restricted: 'a ~ e'One can also define this as $data Reader e v = (e ~ v) => Reader 9^ without GADTs, using explicit coercion as is done here. #newtype Reader e v = Reader (e->v) ^ In the latter case, when we make the request, we make it as Reader id. So, strictly speaking, GADTs are not really necessary.6gGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).7bThe handler of Reader requests. The return type shows that all Reader requests are fully handled.8Locally rebind the value in the dynamic environment This function is like a relay; it is both an admin for Reader requests, and a requestor of them9>Request the environment value using a transformation function.45678945689745 Trustworthy&',-;<=>?FQSTV ;An encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfully= State, strictInitial design: The state request carries with it the state mutator function We can use this request both for mutating and getting the state. But see below for a better design! 3data State s v where State :: (s->s) -> State s sIn this old design, we have assumed that the dominant operation is modify. Perhaps this is not wise. Often, the reader is most nominant.ASee also below, for decomposing the State into Reader and Writer! The conventional design of State@BReturn the current value of the state. The signatures are inferredAWrite a new value of the state.CRun a State effectD$Transform the state with a function.E/Run a State effect, discarding the final state.F.Run a State effect and return the final state.HA different representation of State: decomposing State into mutation (Writer) and Reading. We don't define any new effects: we just handle the existing ones. Thus we define a handler for two effects together.CEffect incorporating State Initial state0Effect containing final state and a return value;<=?>@ABCDEFGH=>?I@ABCDEF;<GH;<=>?Safe&',-;<=>?FQSTVJThe Reader monadThe request for a value of type e from the current environment This can be expressed as a GADT because the type of values returned in response to a (Reader e a) request is not any a; we expect in reply the value of type eM, the value from the environment. So, the return type is restricted: 'a ~ e'One can also define this as $data Reader e v = (e ~ v) => Reader 9^ without GADTs, using explicit coercion as is done here. #newtype Reader e v = Reader (e->v) ^ In the latter case, when we make the request, we make it as Reader id. So, strictly speaking, GADTs are not really necessary.LgGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).MbThe handler of Reader requests. The return type shows that all Reader requests are fully handled.NLocally rebind the value in the dynamic environment This function is like a relay; it is both an admin for Reader requests, and a requestor of them.O>Request the environment value using a transformation function.JKLMNOJKLNOMJK Trustworthy&',-;<=>?FQSTVB QState, lazy (i.e., on-demand)Extensible effects make it clear that where the computation is delayed (which I take as an advantage) and they do maintain the degree of extensibility (the delayed computation must be effect-closed, but the whole computation does not have to be).UBReturn the current value of the state. The signatures are inferredVWrite a new value of the state.YRun a State effectZ$Transform the state with a function.[/Run a State effect, discarding the final state.\.Run a State effect and return the final state.]A different representation of State: decomposing State into mutation (Writer) and Reading. We don't define any new effects: we just handle the existing ones. Thus we define a handler for two effects together.^Backwards state The overall state is represented with two attributes: the inherited getAttr and the synthesized putAttr. At the root node, putAttr becomes getAttr, tying the knot. As usual, the inherited attribute is the argument (i.e., the  environment?) and the synthesized is the result of the handler |go| below._A different notion of  backwards9 is realized if we change the Put handler slightly. How?Another implementation, exploring Haskell's laziness to make putAttr also technically inherited, to accumulate the sequence of updates. This implementation is compatible with deep handlers, and lets us play with different notions of  backwardnessY Initial stateEffect incorporating State0Effect containing final state and a return valueQTSRUVWXYZ[\]^_QRST`UVWXYZ[\]^_QRST  Trustworthy&',-;<=>?FQSTV* aAn encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfullyc State, lazyInitial design: The state request carries with it the state mutator function We can use this request both for mutating and getting the state. But see below for a better design! 3data State s v where State :: (s->s) -> State s sIn this old design, we have assumed that the dominant operation is modify. Perhaps this is not wise. Often, the reader is most nominant.ASee also below, for decomposing the State into Reader and Writer! The conventional design of StatefBReturn the current value of the state. The signatures are inferredgWrite a new value of the state.h$Run a state effect. compared to the runStateL function, this is implemented naively and is expected to perform slower.iCRun a State effect. This variant is a bit optimized compared to  runState'.j$Transform the state with a function.k/Run a State effect, discarding the final state.l.Run a State effect and return the final state.nA different representation of State: decomposing State into mutation (Writer) and Reading. We don't define any new effects: we just handle the existing ones. Thus we define a handler for two effects together.i Initial stateEffect incorporating State0Effect containing final state and a return valueabcedfghijklmncdeofghijklabmnabcde Safe&',-;<=>?FQSTVpIA different implementation, more directly mapping to MonadPlus interfacesAn interpreter The following is very simple, but leaks a lot of memory The cause probably is mapping every failure to empty It takes then a lot of timne and space to store those emptytA different implementation, more involved but faster and taking much less (100 times) less memory. The benefit of the effect framework is that we can have many interpreters.u_Same as makeChoiceA, except it has the type hardcoded. Required for MonadBaseControl instance. prqstuvwx pqr{zystuvwxpqrSafe&'+,-;<=>?FQSTV7|Same as } but with additional  constraint}1A convenient alias to 'SetMember Lift (Lift m) r'~4Catching of dynamic exceptions See the problem in 4http://okmij.org/ftp/Haskell/misc.html#catch-MonadIO|}~}|~ Safe&',-3;<=>?FQSTVG Create unique Enumerable values.6Produce a value that has not been previously produced.&Run an effect requiring unique values. Safe&',-;<=>?FQSTV  Exceptions'exceptions of the type e; no resumptionEThrow an exception in an effectful computation. The type is inferred.Throw an exception in an effectful computation. The type is unit, which suppresses the ghc-mod warning "A do-notation statement discarded a result of type"?Makes an effect fail, preventing future effects from happening.2Run a computation that might produce an exception.<Runs a failable effect, such that failed computation return  , and  the return value on success.Run a computation that might produce exceptions, and give it a way to deal with the exceptions that come up. The handler is allowed to rethrow the exceptionsAdd a default value (i.e. failure handler) to a fallible computation. This hides the fact that a failure happened.iRun a computation until it produces an exception, and convert and throw that exception in a new context.6Treat Lefts as exceptions and Rights as return values. in a lifted MonadLift a maybe into the ! effect, causing failure if it's . in a lifted MonadIgnores a failure event. Since the event can fail, you cannot inspect its return type, because it has none on failure. To inspect it, use .The fallible computation."The computation to run on failure. Safe&',-;<=>?FQSTVNon-determinism (choice)choose lst non-deterministically chooses one value from the lst choose [] thus corresponds to failure Unlike Reader, Choose is not a GADT because the type of values returned in response to a (Choose a) request is just a, without any constraints.fchoose lst non-deterministically chooses one value from the lst choose [] thus corresponds to failure3MonadPlus-like operators are expressible via choose3MonadPlus-like operators are expressible via choose4Run a nondeterministic effect, returning all values.3MonadPlus-like operators are expressible via chooseSafe&',-;<=>?FQSTVSafe&',-3;<=>?FQSTVTrace effect for debuggingPrint a string as a trace.SRun a computation producing Traces. The handler for IO request: a terminal handlerSafe&',-;<=>?FQSTVB -an effectful function that can throw an error >tooBig = do when (i > 100) $ throwError $ show i return i run the tooBig effect based on a provided Int. (runTooBig i = run . runError $ tooBig i  runTooBig 1Right 1 runTooBig 200 Left "200":an effectul computation using state. The state is of type [Int]. This function takes the head off the list, if it is there and return it. If state is the empty list, then it stays the same and returns Nothing. |popState = do stack <- get case stack of [] -> return Nothing (x : xs) -> do put xs return $ Just x qrun the popState effectful computation based on initial state. The result-type is the result of the computation  Maybe Int8 together with the state at the end of the computation [Int] .runPopState xs = run . runState xs $ popState runPopState [1, 2, 3](Just 1,[2,3])runPopState [] (Nothing,[])7an effect that returns a number one more than the given noneMore = do x <- ask -- query the environment return $ x + 1 -- add one to the asked value and return it Run the oneMore1 effectful function by giving it a value to read. +runOneMore i = run . runReader i $ oneMore  runOneMore 12/An effectful computation with multiple effects:A value gets read2an error can be thrown depending on the read valuestate gets read and transformed)All these effects are composed using the Eff- monad using the corresponding Effect types. something = do readValue :: Float <- ask -- read a value from the environment when (readValue < 0) $ throwError readValue -- if the value is negative, throw an error modify (l -> (round readValue :: Integer) : l) -- add the rounded read element to the list currentState :: [Integer] <- get -- get the state after the modification return $ sum currentState -- sum the elements in the list and return that Run the someting effectful computation given in the previous function. The handlers apply from bottom to top - so this is the reading direction. runSomething1 initialState newValue = run . -- run the Eff-monad with no effects left runError . -- run the error part of the effect. This introduces the Either in the result. runState initialState . -- handle the state-effect providing an initial state giving back a pair. runReader newValue $ -- provide the computation with the dynamic value to read/ask for something -- the computation - function runSomething1 [] (-0.5) Left (-0.5)runSomething1 [2] 1.3Right (3,[1,2])Run the  something] effectful computation given above. This has an alternative ordering of the effect-handlers.QThe used effect-handlers are the same are used in slightly different order: The runState and runErrorR methods are swapped, which results in a different output type and run-semantics. runSomething1 initialState newValue = run . runState initialState . runError . runReader newValue $ something -- the computation - function runSomething2 [4] (-2.4)(Left (-2.4),[4])runSomething2 [4] 5.9(Right 10,[6,4])-JKLMNOabcdefghijklmn Safe&',-;<=>?CFQSTVFELift values to an effect. You can think this is a generalization of Lift.Lift a value to a monad.2Convert values using given interpreter to effects.Safe&',-;<=>?FQSTVI!Define data using GADTs.7Then, implements interpreters from the data to effects.Safe&'+,-;<=>?FQSTVQz JThe datatype for the example from the paper. See the tests for the example0specialization to tell the type of the exceptionMultiple Reader effects2Write the elements of a list of numbers, in order.+Add a list of numbers to the current state.:Write a list of numbers and add them to the current state.Sum a list of numbers.aSafely get the last element of a list. Nothing for empty lists; Just the last element otherwise.&Get the last element and sum of a listSafe&',-;<=>?FQSTVZdThe interpreter -- it is like reify . reflect with a twist. Compare this implementation with the huge implementation of call in Hinze 2000 (Figure 9). Each clause corresponds to the axiom of call or cutfalse. All axioms are covered.The code clearly expresses the intuition that call watches the choice points of its argument computation. When it encounteres a cutfalse request, it discards the remaining choicepoints. It completely handles CutFalse effects but not non-determinismSafe&',-3;<=>?FQSTVdStatus of a thread: done or reporting the value of the type a (For simplicity, a co-routine reports a value but accepts unit)Type parameter r# is the effect we're yielding from.Type parameter a is the type that is yielded.Type parameter wO is the type of the value returned from the coroutine when it has completed.QCo-routines The interface is intentionally chosen to be the same as in transf.hsq| The yield request: reporting a value of type e and suspending the coroutine. Resuming with the value of type b2Yield a value of type a and suspend the coroutine.%Launch a thread and report its status !"#$%&'()**+,-./0123456789:;-./0123456789:;<=>?@A;BBCDEFGHIJKLMN;<=>?@A;ODEPFGQHIJKLNRS; B B C D E F G H I J K L M N ; T U V W X Y Z [ \ ; ] ^_`a b b c d ; e f f g h i j k l m n o p q r s ; t t u v w x ] ^ ;yyz{|}~ 1extensible-effects-2.6.3.0-Cwir8dKXWQeBzuBfPFe7tUData.OpenUnionControl.Eff.LiftControl.Eff.Writer.StrictControl.Eff.Writer.LazyControl.Eff.Reader.StrictControl.Eff.State.StrictControl.Eff.Reader.LazyControl.Eff.State.OnDemandControl.Eff.State.LazyControl.Eff.NdetEffControl.Eff.FreshControl.Eff.ExceptionControl.Eff.ChooseControl.Eff.TraceControl.Eff.QuickStartControl.Eff.OperationalControl.Eff.Operational.ExampleControl.Eff.ExampleControl.Eff.CutControl.Eff.Coroutine Data.FTCQueueControl.Eff.Internal Control.Eff SetMember<::MemberinjprjUniondecompweaken$fFindElem[]t[]$fFindElem[]t:$fFindElem[]t:0 $fMembertr $fMembert: $fEQUkBoolabp$fEQUkBoolaaTrue$fMemberU'kFalsetagt:$fMemberU'kTruetagtag:$fSetMemberktagt1:LiftliftrunLiftWriterTelltellcensor runWriter runListWriterrunMonoidWriterrunFirstWriter runLastWriter execWriterexecListWriterexecMonoidWriterexecFirstWriterexecLastWriter$fMonadBaseControlmEffReaderAskask runReaderlocalreaderTxStateStateGetPutgetput runState'runStatemodify evalState execStatetransactionState runStateR OnDemandStateDelayonDemand runStateBack0 runStateBackNdetEffMZeroMPlus makeChoiceA0 makeChoiceA makeChoiceLstmsplitifteonce$fMonadPlusEff$fAlternativeEff LiftedBaseLifted catchDynEFreshfresh runFresh'FailExc throwError throwError_dierunErrorrunFail catchErroronFail rethrowError liftEither liftEitherM liftMaybe liftMaybeM ignoreFailChoosechoosemzero'mplus' makeChoiceTracetracerunTracetooBig runTooBigpopState runPopStateoneMore runOneMore something runSomething1 runSomething2Program Singleton singleton runProgramJailPrintScanprogadventIO adventPureMoveTooBig runErrBigsum2writeAllsumAll writeAndAddsumEfflastEff lastAndSumhandUphandDown $fEqTooBig $fShowTooBigCutFalsecutfalsecallYDoneYieldyieldrunCViewLFTCQueue tsingleton|>><viewlMaptviewlTOne:|LeafNodeEQUFindElemelemNoPunPEffValEArrsArrsingleKqApp^$arridentcomp^|>qCompqCompssendrun handle_relayhandle_relay_s interposeraise $fFunctorEff $fArrowArrs$fCategoryTYPEArrsfirst,monad-control-1.0.2.3-2muMHtg8mYx8DwPZ9oyBonControl.Monad.Trans.ControlMonadBaseControlReplacebaseGHC.BaseNothingJust