!d      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdef g h i j k l m n o p q r s t u v w x y z { | } ~  Safe&',-;<=>?FQSTVSextensible-effectsLeft-edge deconstructionextensible-effectsMNon-empty tree. Deconstruction operations make it more and more left-leaningextensible-effectsThere is no tempty: use (tsingleton return), which works just the same. The names are chosen for compatibility with FastTCQueueextensible-effectssnoc: clearly constant-timeextensible-effectsappend: clearly constant-timeextensible-effects$Process the Left-edge deconstruction Trustworthy&'+,-;<=>?AFQSTV-extensible-effects3This class is used for emulating monad transformersextensible-effectsRUsing overlapping instances here is OK since this class is private to this moduleextensible-effects!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 moduleextensible-effects9A useful operator for reducing boilerplate in signatures.#The following lines are equivalent. A(Member (Exc e) r, Member (State s) r) => ... [ Exc e, State s ]  ::r = ... extensible-effects#Typeclass that asserts that effect t& is contained inside the effect-list r.The FindElemr typeclass is an implementation detail and not required for using the effect list or implementing custom effects.extensible-effects/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 extensible-effectswExplicit 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&',-;<=>?FNQSTVZRextensible-effects%Lifting: emulating monad transformersextensible-effects8The monad that all effects in this library are based on.KAn effectful computation is a value of type `Eff r a`. In this signature, rs is a type-level list of effects that are being requested and need to be handled inside an effectful computation. a5 is the computation's result similar to other monads.0A computation's result can be retrieved via the $h function. However, all effects used in the computation need to be handled by the use of the effects' run*{ functions before unwrapping the final result. For additional details, see the documentation of the effects you are using.extensible-effectsAn 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.extensible-effectsQEffectful arrow type: a function from a to b that also does effects denoted by rextensible-effectsCconvert single effectful arrow into composable type. i.e., convert  to extensible-effectsOApplication to the `generalized effectful function' Arrs r b w, i.e., convert  to extensible-effectsSyntactic sugar for extensible-effectsLift a function to an arrowextensible-effectsThe identity arrowextensible-effectsArrow composition extensible-effectsCommon pattern: append  to !extensible-effects:Compose effectful arrows (and possibly change the effect!)"extensible-effects:Compose effectful arrows (and possibly change the effect!)#extensible-effectsMSend a request and wait for a reply (resulting in an effectful computation).$extensible-effects&Get the result from a pure computationA pure computation has type  Eff '[] aN. The empty effect-list indicates that no further effects need to be handled.%extensible-effectsRA convenient pattern: given a request (open union), either handle it or relay it.&extensible-effectsParameterized handle_relay'extensible-effectstIntercept the request and possibly reply to it, but leave it unhandled (that's why the same r is used all throuout)(extensible-effectsEmbeds a less-constrained 2 into a more-constrained one. Analogous to MTL's ).)extensible-effects*embed an operation of type `m a` into the  monad when Lift m" is in a part of the effect-list.fBy using SetMember, it is possible to assert that the lifted type occurs only once in the effect list*extensible-effects_The handler of Lift requests. It is meant to be terminal: we only allow a single Lifted Monad.extensible-effectsAs the name suggests,  also has an Arrow instance.extensible-effects- can be composed and have a natural identity. !"#$%&'()*Safe&'+,-;<=>?FQSTV_+extensible-effectsSame as , but with additional  constraint,extensible-effects1A convenient alias to 'SetMember Lift (Lift m) r'-extensible-effects4Catching of dynamic exceptions See the problem in 4http://okmij.org/ftp/Haskell/misc.html#catch-MonadIO)*+,-,+)*-Safe&',-;<=>?FQSTV`w !"#$%&'($%&'(# !"Safe&',-;<=>?FQSTVb $$Safe&',-;<=>?FQSTVy .extensible-effectsThe 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 then0extensible-effectsWrite a new value.1extensible-effects#Transform the state being produced.2extensible-effectsjHandle Writer requests, using a user-provided function to accumulate values, hence no Monoid constraints.3extensible-effects:Handle Writer requests, using a List to accumulate values.4extensible-effectsEHandle Writer requests, using a Monoid instance to accumulate values.5extensible-effects:Handle Writer requests by taking the first value provided.6extensible-effects6Handle Writer requests by overwriting previous values.7extensible-effectszHandle Writer requests, using a user-provided function to accumulate values and returning the final accumulated values.8extensible-effectshHandle Writer requests, using a List to accumulate values and returning the final accumulated values.9extensible-effectssHandle Writer requests, using a Monoid instance to accumulate values and returning the final accumulated values.:extensible-effectslHandle Writer requests by taking the first value provided and and returning the final accumulated values.;extensible-effectsdHandle Writer requests by overwriting previous values and returning the final accumulated values../0123456789:;./01256347:;89Safe&',-;<=>?FQSTV =extensible-effectsThe 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?extensible-effectsWrite a new value.@extensible-effects#Transform the state being produced.Aextensible-effectsjHandle Writer requests, using a user-provided function to accumulate values, hence no Monoid constraints.Bextensible-effects:Handle Writer requests, using a List to accumulate values.Cextensible-effectsEHandle Writer requests, using a Monoid instance to accumulate values.Dextensible-effects:Handle Writer requests by taking the first value provided.Eextensible-effects6Handle Writer requests by overwriting previous values.Fextensible-effectszHandle Writer requests, using a user-provided function to accumulate values and returning the final accumulated values.Gextensible-effectshHandle Writer requests, using a List to accumulate values and returning the final accumulated values.Hextensible-effectssHandle Writer requests, using a Monoid instance to accumulate values and returning the final accumulated values.Iextensible-effectslHandle Writer requests by taking the first value provided and and returning the final accumulated values.Jextensible-effectsdHandle Writer requests by overwriting previous values and returning the final accumulated values.=>?@ABCDEFGHIJ=>?@ADEBCFIJGHSafe&',-3;<=>?FQSTV-Lextensible-effectsTrace effect for debuggingNextensible-effectsPrint a string as a trace.Oextensible-effectsSRun a computation producing Traces. The handler for IO request: a terminal handlerLMNOLMNOSafe&',-;<=>?FQSTVPextensible-effectsThe 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.Rextensible-effectsgGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).Sextensible-effectsbThe handler of Reader requests. The return type shows that all Reader requests are fully handled.Textensible-effectsLocally 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 themUextensible-effects>Request the environment value using a transformation function.PQRSTUPQRTUS Trustworthy&',-;<=>?FQSTV Wextensible-effectsAn encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfullyYextensible-effects 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\extensible-effectsBReturn the current value of the state. The signatures are inferred]extensible-effectsWrite a new value of the state._extensible-effectsRun a State effect`extensible-effects$Transform the state with a function.aextensible-effects/Run a State effect, discarding the final state.bextensible-effects.Run a State effect and return the final state.dextensible-effectsA 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._extensible-effectsEffect incorporating Stateextensible-effects Initial stateextensible-effects0Effect containing final state and a return valueWXY[Z\]^_`abcdY[Z\]^_`abWXcd Safe&',-;<=>?FQSTVҎfextensible-effectsThe 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.hextensible-effectsgGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).iextensible-effectsbThe handler of Reader requests. The return type shows that all Reader requests are fully handled.jextensible-effectsLocally 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.kextensible-effects>Request the environment value using a transformation function.fghijkfghjki  Trustworthy&',-;<=>?FQSTV mextensible-effectsState, 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).qextensible-effectsBReturn the current value of the state. The signatures are inferredrextensible-effectsWrite a new value of the state.uextensible-effectsRun a State effectvextensible-effects$Transform the state with a function.wextensible-effects/Run a State effect, discarding the final state.xextensible-effects.Run a State effect and return the final state.yextensible-effectsA 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.zextensible-effectsBackwards 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.{extensible-effectsA 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  backwardnessuextensible-effects Initial stateextensible-effectsEffect incorporating Stateextensible-effects0Effect containing final state and a return valuemponqrstuvwxyz{mponqrstuvwxyz{  Trustworthy&',-;<=>?FQSTV }extensible-effectsAn encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfullyextensible-effects 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 Stateextensible-effectsBReturn the current value of the state. The signatures are inferredextensible-effectsWrite a new value of the state.extensible-effects$Run a state effect. compared to the runStateL function, this is implemented naively and is expected to perform slower.extensible-effectsCRun a State effect. This variant is a bit optimized compared to  runState'.extensible-effects$Transform the state with a function.extensible-effects/Run a State effect, discarding the final state.extensible-effects.Run a State effect and return the final state.extensible-effectsA 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.extensible-effects Initial stateextensible-effectsEffect incorporating Stateextensible-effects0Effect containing final state and a return value}~}~ Safe&',-;<=>?CFQSTVextensible-effectsELift values to an effect. You can think this is a generalization of Lift.extensible-effectsLift a value to a monad.extensible-effects2Convert values using given interpreter to effects. Safe&',-;<=>?FQSTVextensible-effectsDefine data using GADTs.extensible-effects7Then, implements interpreters from the data to effects.Safe&',-;<=>?FQSTV[extensible-effectsIA different implementation, more directly mapping to MonadPlus interfaceextensible-effectsAn 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 emptyextensible-effectsA 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.extensible-effects_Same as makeChoiceA, except it has the type hardcoded. Required for MonadBaseControl instance. Safe&',-3;<=>?FQSTVWextensible-effects Create unique Enumerable values.extensible-effects6Produce a value that has not been previously produced.extensible-effects&Run an effect requiring unique values.Safe&',-;<=>?FQSTV8extensible-effects Exceptions'exceptions of the type e; no resumptionextensible-effectsEThrow an exception in an effectful computation. The type is inferred.extensible-effectsThrow 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"extensible-effects?Makes an effect fail, preventing future effects from happening.extensible-effects2Run a computation that might produce an exception.extensible-effects<Runs a failable effect, such that failed computation return  , and  the return value on success.extensible-effectsRun 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 exceptionextensible-effectssAdd a default value (i.e. failure handler) to a fallible computation. This hides the fact that a failure happened.extensible-effectsiRun a computation until it produces an exception, and convert and throw that exception in a new context.extensible-effects6Treat Lefts as exceptions and Rights as return values.extensible-effects in a lifted Monadextensible-effectsLift a maybe into the ! effect, causing failure if it's .extensible-effects in a lifted Monadextensible-effectsIgnores a failure event. Since the event can fail, you cannot inspect its return type, because it has none on failure. To inspect it, use .extensible-effectsThe fallible computation.extensible-effects"The computation to run on failure.Safe&',-;<=>?FQSTVk{ extensible-effects-an effectful function that can throw an error @tooBig i = do when (i > 100) $ throwError $ show i return i extensible-effectsrun the tooBig effect based on a provided Int. (runTooBig i = run . runError $ tooBig i  runTooBig 1Right 1 runTooBig 200 Left "200"extensible-effects: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 extensible-effectsqrun 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,[])extensible-effects7an 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 extensible-effectsRun the oneMore1 effectful function by giving it a value to read. +runOneMore i = run . runReader i $ oneMore  runOneMore 12extensible-effects/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 extensible-effectsRun 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])extensible-effectsRun 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])-fghijk}~ Safe&'+,-;<=>?FQSTVw extensible-effectsJThe datatype for the example from the paper. See the tests for the exampleextensible-effects0specialization to tell the type of the exceptionextensible-effectsMultiple Reader effectsextensible-effects2Write the elements of a list of numbers, in order.extensible-effects+Add a list of numbers to the current state.extensible-effects:Write a list of numbers and add them to the current state.extensible-effectsSum a list of numbers.extensible-effectsaSafely get the last element of a list. Nothing for empty lists; Just the last element otherwise.extensible-effects&Get the last element and sum of a listSafe&',-3;<=>?FQSTVextensible-effectsStatus 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.extensible-effectsQCo-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 bextensible-effects2Yield a value of type a and suspend the coroutine.extensible-effects%Launch a thread and report its statusSafe&',-;<=>?FQSTVextensible-effectsNon-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.extensible-effectsfchoose lst non-deterministically chooses one value from the lst choose [] thus corresponds to failureextensible-effects3MonadPlus-like operators are expressible via chooseextensible-effects3MonadPlus-like operators are expressible via chooseextensible-effects4Run a nondeterministic effect, returning all values.extensible-effects3MonadPlus-like operators are expressible via chooseSafe&',-;<=>?FQSTVextensible-effectsThe 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-determinism !"#$%&'()*++,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTFGHIJKLMNOPQRSTUUVWXYZ[\]T^^_`abcdefghijT X Y Z [ \ ] T k ` a l b c m d e f g h j n o T ^ ^ _ ` a b c d e f g h i j T p q r s t u v w x yz{|}~TTTT/1extensible-effects-3.1.0.1-4sNKqkyxVsKKsV3UW27ixQData.OpenUnionControl.Eff.LiftControl.Eff.ExtendControl.Eff.Writer.StrictControl.Eff.Writer.LazyControl.Eff.TraceControl.Eff.Reader.StrictControl.Eff.State.StrictControl.Eff.Reader.LazyControl.Eff.State.OnDemandControl.Eff.State.LazyControl.Eff.OperationalControl.Eff.Operational.ExampleControl.Eff.NdetEffControl.Eff.FreshControl.Eff.ExceptionControl.Eff.QuickStartControl.Eff.ExampleControl.Eff.CoroutineControl.Eff.ChooseControl.Eff.Cut Data.FTCQueueControl.Eff.Internal Control.Eff SetMember<::MemberinjprjUniondecompweaken$fFindElem[]t[]$fFindElem[]t:$fFindElem[]t:0 $fMembertr $fMembert: $fEQUkBoolabp$fEQUkBoolaaTrue$fMemberU'kFalsetagt:$fMemberU'kTruetagtag:$fSetMemberktagt1:LiftEffValEArrsArrfirstsingleKqApp^$arridentcomp^|>qCompqCompssendrun handle_relayhandle_relay_s interposeraiseliftrunLift LiftedBaseLifted catchDynEWriterTelltellcensor runWriter runListWriterrunMonoidWriterrunFirstWriter runLastWriter execWriterexecListWriterexecMonoidWriterexecFirstWriterexecLastWriter$fMonadBaseControlmEffTracetracerunTraceReaderAskask runReaderlocalreaderTxStateStateGetPutgetput runState'runStatemodify evalState execStatetransactionState runStateR OnDemandStateDelayonDemand runStateBack0 runStateBackProgram Singleton singleton runProgramJailPrintScanprogadventIO adventPureNdetEffMZeroMPlus makeChoiceA0 makeChoiceA makeChoiceLstmsplitifteonce$fMonadPlusEff$fAlternativeEffFreshfresh runFresh'FailExc throwError throwError_dierunErrorrunFail catchErroronFail rethrowError liftEither liftEitherM liftMaybe liftMaybeM ignoreFailtooBig runTooBigpopState runPopStateoneMore runOneMore something runSomething1 runSomething2MoveTooBig runErrBigsum2writeAllsumAll writeAndAddsumEfflastEff lastAndSumhandUphandDown $fEqTooBig $fShowTooBigYDoneYieldyieldrunCChoosechoosemzero'mplus' makeChoiceCutFalsecutfalsecallViewLFTCQueue tsingleton|>><viewlMaptviewlEQUFindElem $fArrowArrs$fCategoryTYPEArrs,monad-control-1.0.2.3-IPrpWAjYxOt1opqDMU7GN2Control.Monad.Trans.ControlMonadBaseControlbaseGHC.BaseNothingJust