!I9J      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      Safe&'-.=>?@AHSUVXextensible-effectsLeft-edge deconstructionextensible-effectsNNon-empty tree. Deconstruction operations make it more and more left-leaning.extensible-effects There is no tempty: use (tsingleton returnV), 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%&',-.=>?@ACHSUVXg5] extensible-effects3This class is used for emulating monad transformersextensible-effectsRUsing overlapping instances here is OK since this class is private to this moduleextensible-effectsFind the index of an element in a type-level 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 rextensible-effects9U1 : everything excluding the first element of the union.extensible-effectsCSome helpful pattern synonyms. U0 : the first element of the unionextensible-effects5Pattern synonym to project the union onto the effect t. extensible-effects9Orthogonal decomposition of the union: head and the rest.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&',-.=>?@AHPSUVX_k"extensible-effectsYou need this when using :.extensible-effectsSame as  but with additional   constraintextensible-effectsA convenient alias to SetMember Lift (Lift m) rU, which allows us to assert that the lifted type occurs ony once in the effect list.extensible-effects%Lifting: emulating monad transformersextensible-effectsRespond to requests of type tA. The handlers themselves are expressed in open-recursion style.extensible-effectspA convenient pattern: given a request (in an open union), either handle it (using default Handler) or relay it.Handle# implies that all requests of type t are dealt with, i.e., k# (the response type) doesn't have t! as part of its effect list. The  Relay k r constraint ensures that k/ is an effectful computation (with effectlist r).MNote that we can only handle the leftmost effect type (a consequence of the  implementation.extensible-effectsOIntercept the request and possibly respond to it, but leave it unhandled. The  Relay k r constraint ensures that k/ is an effectful computation (with effectlist r). As such, the effect type t$ will show up in the response type k/. There are two natural / commmon options for k: the implicit effect domain (i.e., Eff r (f a)), or the explicit effect domain (i.e., s1 -> s2 -> ... -> sn -> Eff r (f a s1 s2 ... sn)).GThere are three different ways in which we may want to alter behaviour: Before": This work should be done before  is called.DuringD: This work should be done by altering the handler being passed to 5. This allows us to modify the requests "in flight".After+: This work should be done be altering the ret being passed to . This allows us to overwrite changes or discard them altogether. If this seems magical, note that we have the flexibility of altering the target domain k. Specifically, the explicit domain representation gives us access to the "effect" realm allowing us to manipulate it directly. extensible-effectsAbstract the recursive !* pattern, i.e., "somebody else's problem"."extensible-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, rt 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 3h 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 ! and " instances.&extensible-effectsQEffectful arrow type: a function from a to b that also does effects denoted by r(extensible-effectsCconvert single effectful arrow into composable type. i.e., convert & to %)extensible-effects4Application to the `generalized effectful function'  Arrs r b w, i.e., convert % to &*extensible-effectsSyntactic sugar for )+extensible-effectsLift a function to an arrow,extensible-effectsThe identity arrow-extensible-effectsArrow composition.extensible-effectsCommon pattern: append & to %/extensible-effectsCase analysis for " datatype. If the value is # a apply the first function to a ; if it is $ u q, apply the second function.#extensible-effects The usual #D fnuction with arguments flipped. This is a common pattern for Eff.0extensible-effects:Compose effectful arrows (and possibly change the effect!)1extensible-effects:Compose effectful arrows (and possibly change the effect!)2extensible-effectsMSend a request and wait for a reply (resulting in an effectful computation).3extensible-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.4extensible-effectsEA less commonly needed variant with an explicit handler (instead of Handle t r a k constraint).5extensible-effects-Variant with an explicit handler (instead of Handle t r a k constraint).6extensible-effectsEmbeds a less-constrained "2 into a more-constrained one. Analogous to MTL's 7.7extensible-effects*embed an operation of type `m a` into the " monad when Lift m" is in a part of the effect-list.8extensible-effectsThe handler of Lift requests. It is meant to be terminal: we only allow a single Lifted Monad. Note, too, how this is different from other handlers.9extensible-effects4Catching of dynamic exceptions See the problem in 4http://okmij.org/ftp/Haskell/misc.html#catch-MonadIO:extensible-effectsCatch multiple dynamic exceptions. The implementation follows that in Control.Exception almost exactly. Not yet tested. Could this be useful for control with cut?$extensible-effectsAs the name suggests, % also has an " instance.%extensible-effects%- can be composed and have a natural identity.&extensible-effects3Handle lifted requests by running them sequentiallyextensible-effectsuntied recursive knotextensible-effectscoroutine awaiting responseextensible-effectsrequestextensible-effectsreturnextensible-effectsuntied recursive knotextensible-effectsreturnextensible-effectsuntied recursive knot4extensible-effectshandlerextensible-effectsreturnextensible-effectsuntied recursive knot5extensible-effectshandlerextensible-effectsreturnextensible-effectsrecursive knot( !"#$%'&'()*+,-./#0123456789:Safe&'-.=>?@AHSUVXg0  !"$#%&'()*+,-./0123456789:0"$#3/789:   !4562&%'()*+,-.01Safe&'-.=>?@AHSUVX&"3789:3"789:Safe&'-.=>?@AHSUVX;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-effectsOHow to interpret a pure value in a writer context, given the value for mempty.>extensible-effectsWrite a new value.?extensible-effects#Transform the state being produced.@extensible-effectsjHandle Writer requests, using a user-provided function to accumulate values, hence no Monoid constraints.Aextensible-effects:Handle Writer requests, using a List to accumulate values.Bextensible-effectsEHandle Writer requests, using a Monoid instance to accumulate values.Cextensible-effects:Handle Writer requests by taking the first value provided.Dextensible-effects6Handle Writer requests by overwriting previous values.Eextensible-effectszHandle Writer requests, using a user-provided function to accumulate values and returning the final accumulated values.Fextensible-effectshHandle Writer requests, using a List to accumulate values and returning the final accumulated values.Gextensible-effectssHandle Writer requests, using a Monoid instance to accumulate values and returning the final accumulated values.Hextensible-effectslHandle Writer requests by taking the first value provided and and returning the final accumulated values.Iextensible-effectsdHandle Writer requests by overwriting previous values and returning the final accumulated values.Kextensible-effects_Given a value to write, and a callback (which includes empty and append), respond to requests.;<=>?@ABCDEFGHI;<=>?@CDABEHIFGSafe&'-.=>?@AHSUVXk&Lextensible-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 thenNextensible-effectsOHow to interpret a pure value in a writer context, given the value for mempty.Oextensible-effectsWrite a new value.Pextensible-effects#Transform the state being produced.Qextensible-effectsjHandle Writer requests, using a user-provided function to accumulate values, hence no Monoid constraints.Rextensible-effects:Handle Writer requests, using a List to accumulate values.Sextensible-effectsEHandle Writer requests, using a Monoid instance to accumulate values.Textensible-effects:Handle Writer requests by taking the first value provided.Uextensible-effects6Handle Writer requests by overwriting previous values.Vextensible-effectszHandle Writer requests, using a user-provided function to accumulate values and returning the final accumulated values.Wextensible-effectshHandle Writer requests, using a List to accumulate values and returning the final accumulated values.Xextensible-effectssHandle Writer requests, using a Monoid instance to accumulate values and returning the final accumulated values.Yextensible-effectslHandle Writer requests by taking the first value provided and and returning the final accumulated values.Zextensible-effectsdHandle Writer requests by overwriting previous values and returning the final accumulated values.\extensible-effects_Given a value to write, and a callback (which includes empty and append), respond to requests.LMNOPQRSTUVWXYZLMNOPQTURSVYZWXSafe&'-.4=>?@AHSUVXJ]extensible-effectsTrace effect for debugging_extensible-effects#Embed a pure value in Trace context`extensible-effectsPrint a string as a trace.aextensible-effectsSRun a computation producing Traces. The handler for IO request: a terminal handlerbextensible-effects+Given a callback and request, respond to it]^_`a]^_`aSafe&'-.=>?@AHSUVXkEcextensible-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.eextensible-effects1How to interpret a pure value in a reader contextfextensible-effectsgGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).gextensible-effectsbThe handler of Reader requests. The return type shows that all Reader requests are fully handled.hextensible-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.iextensible-effects>Request the environment value using a transformation function.kextensible-effectsCGiven a value to read, and a callback, how to respond to requests.cdefghicdefhig Trustworthy&'-.=>?@AHSUVXk lextensible-effectsAn encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfullynextensible-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 Stateqextensible-effectsEmbed a pure value in a stateful computation, i.e., given an initial state, how to interpret a pure value in a stateful computation.rextensible-effectsBReturn the current value of the state. The signatures are inferredsextensible-effectsWrite a new value of the state.textensible-effectsRun a State effectuextensible-effects$Transform the state with a function.vextensible-effects/Run a State effect, discarding the final state.wextensible-effects.Run a State effect and return the final state.xextensible-effects8Embed Transactional semantics to a stateful computation.yextensible-effects9Confer transactional semantics on a stateful computation.zextensible-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-effectsHandle 'State s' requeststextensible-effects Initial stateextensible-effectsEffect incorporating Stateextensible-effects0Effect containing final state and a return valuelmnpoqrstuvwxyznpoqrstuvwlmxyzSafe&'-.=>?@AHSUVXkO}extensible-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.extensible-effects1How to interpret a pure value in a reader contextextensible-effectsgGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).extensible-effectsbThe handler of Reader requests. The return type shows that all Reader requests are fully handled.extensible-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.extensible-effects>Request the environment value using a transformation function.extensible-effectsCGiven a value to read, and a callback, how to respond to requests.}~}~  Trustworthy&'-.=>?@AHSUVXk5 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-effectsEmbed a pure value in a stateful computation, i.e., given an initial state, how to interpret a pure value in a stateful computation.extensible-effectsBReturn the current value of the state. The signatures are inferredextensible-effectsWrite a new value of the state.extensible-effectsRun a State effectextensible-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-effects8Embed Transactional semantics to a stateful computation.extensible-effects9Confer transactional semantics on a stateful computation.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-effectsHandle 'State s' requestsextensible-effects Initial stateextensible-effectsEffect incorporating Stateextensible-effects0Effect containing final state and a return value  Trustworthy&'-.=>?@AHSUVXR extensible-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).extensible-effectsBReturn the current value of the state. The signatures are inferredextensible-effectsWrite a new value of the state.extensible-effectsRun a State effectextensible-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-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-effectsXA different notion of backwards 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 backwardness.extensible-effects)Given a continuation, respond to requestsextensible-effects Initial stateextensible-effectsEffect incorporating Stateextensible-effects0Effect containing final state and a return value Safe&'-.=>?@AEHSUVXZIextensible-effectsGeneral form of an interpreterextensible-effectsELift values to an effect. You can think this is a generalization of Lift.extensible-effectsEmbed a pure valueextensible-effectsLift a value to a monad.extensible-effects2Convert values using given interpreter to effects.extensible-effectsCGiven a continuation and a program, interpret it Usually, we have r ~ [Program f : r'] Safe&'-.=>?@AHSUVX]extensible-effectsDefine data using GADTs.extensible-effects7Then, implements interpreters from the data to effects. Safe&'-.4=>?@AHSUVXcextensible-effects Create unique Enumerable values.extensible-effectsaEmbed a pure value. Note that this is a specialized form of State's and we could have reused it.extensible-effects6Produce a value that has not been previously produced.extensible-effects&Run an effect requiring unique values.extensible-effects2Given a continuation and requests, respond to themSafe&'-.=>?@AHSUVXextensible-effects Exceptions'exceptions of the type e; no resumptionextensible-effectsEmbed a pure valueextensible-effectsThrow an errorextensible-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-effectsGiven a callback, and an  request, respond to it.extensible-effectsThe fallible computation.extensible-effects"The computation to run on failure.Safe&'-.=>?@AHSUVXr 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])2}~ Safe%&'-.=>?@AHSUVX_extensible-effectsNon-determinism with control (cut).CFor the explanation of cut, see Section 5 of Hinze ICFP 2000 paper:[Backtr] 0https://dl.acm.org/citation.cfm?id=351240.351258(Deriving Backtracking Monad TransformersHinze suggests expressing cut in terms of cutfalse: 3= return () `mplus` cutfalse where cutfalse :: m asatisfies the following laws: [ cutfalse >>= k = cutfalse (F1) cutfalse | m = cutfalse (F2)(note: m `* ` cutfalse is different from  cutfalse `*` mE). In other words, cutfalse is the left zero of both bind and mplus.$Hinze also introduces the operation  :: m a -> m a# that delimits the effect of cut:  m executes m. If the cut is invoked in m, it discards only the choices made since m was called. Hinze postulates the axioms of :  call false = false (C1) call (return a | m) = return a | call m (C2) call (m | cutfalse) = call m (C3) call (lift m >>= k) = lift m >>= (call . k) (C4) m behaves like m except any cut inside m# has only a local effect, he says.Hinze noted a problem with the "mechanical" derivation of backtracing monad transformer with cut: no axiom specifying the interaction of call with bind; no way to simplify nested invocations of call.extensible-effectsMapping Backtr interface to + and using exceptions for cutfalse<, every instance should ensure that the following laws hold: + cutfalse `mplus` m = cutfalse --(F2) call mzero = mzero --(C1) call (return a `mplus` m) = return a `mplus` call m --(C2) call (m `mplus` cutfalse) = call m --(C3) call (lift m >>= k) = lift m >>= (call . k) --(C4)extensible-effects'The MSplit primitive from LogicT paper.extensible-effects The laws for  are: ^msplit mzero = return Nothing msplit (return a `mplus` m) = return (Just(a, m))extensible-effectsEmbed a pure value into MSplitextensible-effects Laws for : msplit (lift m >> mzero) >>= reflect = lift m >> mzero msplit (lift m `mplus` ma) >>= reflect = lift m `mplus` (msplit ma >>= reflect)extensible-effects7Soft-cut: non-deterministic if-then-else, aka Prolog's *-> Declaratively, 2 ifte t th el = (t >>= th) `mplus` ((not t) >> el) However, t) is evaluated only once. In other words,  ifte t th el is equivalent to t >>= th if t has at least one solution. If t fails,  ifte t th el is the same as el. Laws: ifte (return a) th el = th a ifte mzero th el = el ifte (return a `mplus` m) th el = th a `mplus` (m >>= th)extensible-effects_Another pruning operation (ifte is the other). This selects one solution out of possibly many.extensible-effectsNegation as failureextensible-effectsIFair (i.e., avoids starvation) disjunction. It obeys the following laws: qinterleave mzero m = m interleave (return a `mplus` m1) m2 = return a `mplus` (interleave m2 m1) corollary: interleave m mzero = mextensible-effectsIFair (i.e., avoids starvation) conjunction. It obeys the following laws: Zmzero >>- k = mzero (return a `mplus` m) >>- k = interleave (k a) (m >>- k)extensible-effects,Collect all solutions. This is from Hinze's BacktrJ monad class. Unsurprisingly, this can be implemented in terms of msplit.extensible-effects3We use exceptions for cutfalse Therefore, the law cutfalse >>= k = cutfalseJ is satisfied automatically since all exceptions have the above property.extensible-effectsProlog cutD, taken from Hinze 2000 (Deriving backtracking monad transformers).extensible-effectsCase analysis for listsSafe&'-.1=>?@AHSUVX_kGextensible-effectsjAn implementation of non-deterministic choice aka backtracking. The two requests we need to support are: false, (|). We map this to the + (or , ) interface: MZero stands for false, and MPlus stands for (|).4This creates a branching structure with a fanout of 2, resulting in mplus# node being visited approximately 2x (in general, for a fanout of f5 we'll have the type of internal node being invoked f/(f-1) times).extensible-effects6How to embed a pure value in non-deterministic contextextensible-effectsThe left branchextensible-effectsThe right branchextensible-effects lst3 non-deterministically chooses one value from the lst.  [] thus corresponds to failure.extensible-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 empty. When there aren't a lot of failures, this is comparable to .-extensible-effects.Progressing the cursor in a reified job queue.extensible-effectsOptimized implementation, faster and taking less memory. The benefit of the effect framework is that we can have many interpreters.extensible-effectsFA different implementation, more involved, but similar complexity to .extensible-effectsSame as 2, except it has the type hardcoded. Required for   instance.extensible-effectsThe implementation of >. Exported as a standalone to make testing/comparison easier.extensible-effectsFA different implementation, more involved, but similar complexity to .extensible-effectsThe call 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-determinismextensible-effectsWe implement LogicT, the non-determinism reflection, of which soft-cut is one instance. See the LogicT paper for an explanation.extensible-effects/More performant handler; uses reified job queueextensible-effects Mapping of  requests to +.. We obey the following laws (taken from the Backtr and @LogicT papers): !mzero >>= f = mzero -- (L1) mzero `mplus` m = m -- (L2) m `mplus` mzero = m -- (L3) m `mplus` (n `mplus` o) = (m `mplus` n) `mplus` o -- (L4) (m `mplus` n) >>= k = (m >>= k) `mplus` (n >>= k) -- (L5)L1 is the left-zero law for . L2, L3, L4 are the Monoid lawsNOTE that we do not obey the right-zero law for .. Specifically, we do not obey: m >> mzero = mzeroextensible-effectsGiven a callback and J requests respond to them. Note that this makes explicit that we rely on f0 to have enough room to store all possibilities. Safe&'-.=>?@AHSUVX Safe&',-.=>?@AHSUVX+W 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 list      Safe&'-.4=>?@AHSUVX9extensible-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-effectsReturn a pure valueextensible-effects%Launch a thread and report its statusextensible-effects1Given a continuation and a request, respond to it/ !"#$%&'()*+,-.//01223456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcSTUVWXYZ[\]^_`abcddefghijklmnobpqqrstuvwxyz{|}~bijklmnobp  q q r s t u v w x y z { | } ~ b   s t  v w x y z { ~ b          b bb= 1extensible-effects-5.0.0.0-96S90DnNqckDf93qqwQh6yData.OpenUnionControl.Eff.ExtendControl.Eff.Writer.StrictControl.Eff.Writer.LazyControl.Eff.TraceControl.Eff.Reader.StrictControl.Eff.State.StrictControl.Eff.Reader.LazyControl.Eff.State.LazyControl.Eff.State.OnDemandControl.Eff.OperationalControl.Eff.Operational.ExampleControl.Eff.FreshControl.Eff.ExceptionControl.Eff.QuickStartControl.Eff.Logic.CoreControl.Eff.Logic.NDetControl.Eff.ExampleControl.Eff.Coroutine Data.FTCQueueControl.Eff.InternalData OpenUnion Control.EffControl.Eff.Logic.Experimental SetMember<::MemberinjprjUnionU1U0U0'decompweaken$fFindElem[]t[]$fFindElem[]t:$fFindElem[]t:0 $fMembertr $fMembert: $fEQUkBoolabp$fEQUkBoolaaTrue$fMemberU'kFalsetagt:$fMemberU'kTruetagtag:$fSetMemberktagt1: HandlerDynE LiftedBaseLiftedLiftunLiftHandlehandle handle_relay respond_relayRelayrelayEffValEArrsArrfirstsingleKqApp^$arridentcomp^|>effqCompqCompssendrun handle_relay'respond_relay'raiseliftrunLift catchDynE catchesDynEWriterTell withWritertellcensor runWriter runListWriterrunMonoidWriterrunFirstWriter runLastWriter execWriterexecListWriterexecMonoidWriterexecFirstWriterexecLastWriter$fMonadBaseControlmEff$fHandleWriterra->Trace withTracetracerunTrace$fHandleTraceraIOReaderAsk withReaderask runReaderlocalreader$fHandleReaderra->TxStateStateGetPut withStategetputrunStatemodify evalState execState withTxStatetransactionState runStateR$fHandleStatera->TxStateT OnDemandStateDelayonDemand runStateBack0 runStateBack$fHandleOnDemandStatera->Intrprtr runIntrprtrProgram SingletonwithOperational singleton runProgram$fHandleProgramra->JailPrintScanprogadventIO adventPureFresh withFreshfresh runFresh'$fHandleFreshra->FailExc withExceptionexc throwError throwError_dierunErrorrunFail catchErroronFail rethrowError liftEither liftEitherM liftMaybe liftMaybeM ignoreFail$fHandleExcramtooBig runTooBigpopState runPopStateoneMore runOneMore something runSomething1 runSomething2CutFalseCallcallMSplitmsplit withMSplitreflectifteoncegnot interleave>>-solscutfalse!listNDetwithNDetleftrightchoose makeChoiceA0 makeChoiceAmakeChoiceA_manual makeChoicemsplit'msplit'_manual$fCallr $fMSplitEff$fHandleNDetra->$fMonadPlusEff$fAlternativeEff$fHandleNDetraEffMoveTooBig runErrBigsum2writeAllsumAll writeAndAddsumEfflastEff lastAndSumhandUphandDown $fEqTooBig $fShowTooBigYDoneYieldyield withCoroutinerunC$fHandleYield:wEffViewLFTCQueue tsingleton|>><viewlMaptviewlEQUFindElem,monad-control-1.0.2.3-7nkbYj3vGDkFaD9mDe8p7yControl.Monad.Trans.ControlMonadBaseControlbaseControl.CategoryCategory Control.ArrowArrowbind $fArrowArrs$fCategoryTYPEArrs$fHandleLiftram GHC.MaybeNothingJustGHC.Basemplus MonadPlus Alternativenextmzero