úÎ hÁ      !"#$%&'()*+,-./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&'QVkÁLeft-edge deconstructionÂMNon-empty tree. Deconstruction operations make it more and more left-leaningĂ€There is no tempty: use (tsingleton return), which works just the same. The names are chosen for compatibility with FastTCQueueÄsnoc: clearly constant-timeĹappend: clearly constant-timeĆ$Process the Left-edge deconstructionÁÂĂÄĹĆÇÁČÉÂĘË Trustworthy&',-;<=>?AFSTV­3This class is used for emulating monad transformersĚRUsing 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/The data constructors of Union are not exportedĹStrong 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 ÍÎĎĐŃŇ Trustworthy &'-NQSTV>„\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_relay#WAdd 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)&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-<QSTVJ6)The Writer monadćIn 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.0:Handle Writer requests by taking the first value provided.16Handle Writer requests by overwriting previous values. )*+,-./01 )*+,-01./)*Safe-<QSTVUC2The Writer monadćIn 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 then4Write a new value.5#Transform the state being produced.6jHandle Writer requests, using a user-provided function to accumulate values, hence no Monoid constraints.7:Handle Writer requests, using a List to accumulate values.8EHandle Writer requests, using a Monoid instance to accumulate values.9:Handle Writer requests by taking the first value provided.:6Handle Writer requests by overwriting previous values. 23456789: 234569:7823Safe&'-3<STX@;Trace effect for debugging=Print a string as a trace.>SRun a computation producing Traces. The handler for IO request: a terminal handler;<=>;<=>;<Safe &'-<STVe ?ĽDefine a new effect for state on-demand (in ExtEff, the state is by default strict -- as it should be if we want the predictable performance and effect sequencing)CPrimitive state operationsG The handlerHő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.Iě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 ?BA@CDEFGHI ?@ABCDEFGHI?@ABSafe-<QSTVv\JThe Reader monadßThe 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 e|, the value from the environment. So, the return type is restricted: 'a ~ e' data Reader e v where Reader :: Reader e e…One can also define this as data Reader e v = (e ~ v) => Reader and even without GADTs, using explicit coercion as is done here.~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.N”Locally 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 themO>Request the environment value using a transformation function.JKLMNOJKLNOMJK Trustworthy &'-<QSTV‰Ţ P‹An encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfullyR State, strictłInitial 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 s‰In 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 StateUBReturn the current value of the state. The signatures are inferredVWrite a new value of the state.XRun a State effectY$Transform the state with a function.Z/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.XEffect incorporating State Initial state0Effect containing final state and a return valuePQRTSUVWXYZ[\]RSTUVWXYZ[PQ\]PQRST Safe-<QSTVœ^The Reader monadßThe 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 e|, the value from the environment. So, the return type is restricted: 'a ~ e' data Reader e v where Reader :: Reader e e…One can also define this as data Reader e v = (e ~ v) => Reader and even without GADTs, using explicit coercion as is done here.~In the latter case, when we make the request, we make it as Reader id. So, strictly speaking, GADTs are not really necessary.`gGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).abThe handler of Reader requests. The return type shows that all Reader requests are fully handled.bĐLocally 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. The underscore is used to disable name-shadowing warning.c>Request the environment value using a transformation function.^_`abc^_`bca^_  Trustworthy &'-<QSTV´› dState, 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).hBReturn the current value of the state. The signatures are inferrediWrite a new value of the state.lRun a State effectm$Transform the state with a function.n/Run a State effect, discarding the final state.o.Run a State effect and return the final state.pÓ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.qő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.rA 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  backwardnesslEffect incorporating State Initial state0Effect containing final state and a return valuedfgehijklmnopqrdefghijklmnopqrdefg Safe -<>?CQSTV¸#sELift values to an effect. You can think this is a generalization of Lift.uLift a value to a monad.v2Convert values using given interpreter to effects.stuvstuvst Safe &'-<QSTVż¸wIA different implementation, more directly mapping to MonadPlus interfacezşAn 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{°A 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.wyxz{|}~ wxy€z{|}~wxy Safe-<QVŁ%Lifting: emulating monad transformersƒ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.…4Catching of dynamic exceptions See the problem in 4http://okmij.org/ftp/Haskell/misc.html#catch-MonadIO‚ƒ„…‚ƒ„…‚Safe&'<Ćî†Define data using GADTs.Š7Then, implements interpreters from the data to effects.†ˆ‡‰Š‹†‡ˆ‰Š‹†‡ˆSafe &'-3<>?STÉťŒ Create unique Enumerable values.Ž6Produce a value that has not been previously produced.&Run an effect requiring unique values.ŒŽŒŽŒSafe-<QSTVۆ ‘ Exceptions'exceptions of the type e; no resumption“EThrow an exception in an effectful computation. The type is inferred.”?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 exception˜sAdd 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 MonadœLift a maybe into the ! effect, causing failure if it's Ó.œ in a lifted MonadžIgnores 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&'-<STăoĄJThe datatype for the example from the paper. See the tests for the exampleŁ0specialization to tell the type of the exception¤2Write 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 list Ÿ Ą˘Ł¤ĽŚ§¨ŠŞŤ Ą˘Ł¤ĽŚ§¨ŠŸ ŞŤŸ Ą˘Safe-3<STíStatus 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 bł2Yield a value of type a and suspend the coroutine.´%Launch a thread and report its statusŽŻ°ą˛ł´ą˛ł´ŽŻ°Žݰą˛Safe-<QSTV÷řľNon-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 failure¸3MonadPlus-like operators are expressible via chooseš3MonadPlus-like operators are expressible via chooseş4Run a nondeterministic effect, returning all values.ź3MonadPlus-like operators are expressible via chooseľśˇ¸šşľśˇş¸šľśSafe-<ST9ŔíThe 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:;<=>>?@ABCDE>>?@ABCDEFFGHIJKLMNOPQRSTTUVWXYYZ[\]^_`abcde T T U V W X Z [ \ L ] ^ P _ ` a b c e R S f f g h i j k l m n o p q r s s t u vwxyz{|}}~€‚ƒ„…†‡ˆ‰Š‹ŒŽŽ‘’“”•–—˜™š››œžŸ  Ą˘Ł¤qrĽĽŚ§¨ŠŞŤŹ­ŽŻ°ą˛ł´ľśśˇ¸šş¸šťź1extensible-effects-2.2.1.0-5kP62321KYPBakgZYkOMX5Data.OpenUnion Control.EffControl.Eff.Writer.StrictControl.Eff.Writer.LazyControl.Eff.TraceControl.Eff.State.LazyStateControl.Eff.Reader.StrictControl.Eff.State.StrictControl.Eff.Reader.LazyControl.Eff.State.LazyControl.Eff.OperationalControl.Eff.NdetEffControl.Eff.LiftControl.Eff.Operational.ExampleControl.Eff.FreshControl.Eff.ExceptionControl.Eff.ExampleControl.Eff.CoroutineControl.Eff.ChooseControl.Eff.Cut Data.FTCQueue SetMemberMemberinjprjUniondecompweaken$fFindElem[]t:$fFindElem[]t:0 $fMembertr $fEQUkBoolabp$fEQUkBoolaaTrue$fMemberU'kFalsetagt:$fMemberU'kTruetagtag:$fSetMemberktagt1:EffValEArrsArrfirstsingleKqApp^$arridentcomp^|>qCompqCompssendrun handle_relayhandle_relay_s interpose $fMonadEff$fApplicativeEff $fFunctorEff $fArrowArrs$fCategoryTYPEArrsWritertellcensor runWriter runListWriterrunMonoidWriterrunFirstWriter runLastWriterTracetracerunTrace LazyStateLGetLPutDelaylgetlputlmodifyonDemand runStateLazy runStateBack0 runStateBackReaderask runReaderlocalreader ProxyStateStateGetPutgetput runState'runStatemodify evalState execStatetransactionState runStateRProgram singleton runProgramNdetEffMZeroMPlus makeChoiceA0 makeChoiceAmsplitifteonce$fMonadPlusEff$fAlternativeEffLiftliftrunLift catchDynEJailPrintScanprogadventIO adventPureFreshfresh runFresh'FailExcthrowExcdierunExcrunFailcatchExconFail rethrowExc liftEither liftEitherM liftMaybe liftMaybeM ignoreFailMoveTooBig runErrBigwriteAllsumAll writeAndAddsumEfflastEff lastAndSumhandUphandDown $fEqTooBig $fShowTooBigYDoneYieldyieldrunCChoosechoosemzero'mplus' makeChoiceCutFalsecutfalsecallViewLFTCQueue tsingleton|>><viewlMaptviewlTOne:|LeafNodeEQUFindElemelemNoPunPbaseGHC.BaseNothingJust