#       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQ R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o pqrstuvwxyz{|}~ Trustworthy%&+,9:;<=?DQRT3This 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   Safe%&Left-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  Trustworthy %&,LOQRT \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 b that is a composition of several effectful functions. The paremeter r describes the overall effect. The composition members are accumulated in a type-aligned queuecA monadic library for communication between a handler and its client, the administered computationQEffectful arrow type: a function from a to b that also does effects denoted by r>Application to the `generalized effectful function' Arrs r b w: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)"bEff is still a monad and a functor (and Applicative) (despite the lack of the Functor constraint) !""!  !"Safe,:OQRT#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.#$%&'(#$%&'(#$%(&'#$%&'(Safe,2:QR)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 %&,2:<=QR0 Create unique Enumerable values.26Produce a value that has not been previously produced.3&Run an effect requiring unique values.0123012301230123Safe,:4%Lifting: emulating monad transformers64We make the Lift layer to be unique, using SetMember7_The handler of Lift requests. It is meant to be terminal: we only allow a single Lifted Monad.4567456745674567Safe,:OQRT 9 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.AiRun a computation until it produces an exception, and convert and throw that exception in a new context.B6Treat Lefts as exceptions and Rights as return values.CB in a lifted MonadDLift a maybe into the 8! effect, causing failure if it's .ED in a lifted MonadFIgnores a failure event. Since the event can fail, you cannot inspect its return type, because it has none on failure. To inspect it, use >.89:;<=>?@The fallible computation."The computation to run on failure.ABCDEF89:;<=>?@ABCDEF9:8;<=>?@ABCDEF89:;<=>?@ABCDEFSafe %&,:OQRTGIA different implementation, more directly mapping to MonadPlus interfaceJAn 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 emptyKA 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. GHIJKLMNOPGHIJKLMN GHIPOJKLMNGHIJKLMNOP Safe ,:<=AOQRTQELift values to an effect. You can think this is a generalization of Lift.SLift a value to a monad.T2Convert values using given interpreter to effects.QRSTQRSTQRSTQRST Safe,:OQRTUThe 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 e|, the value from the environment. So, the return type is restricted: 'a ~ e' data Reader e v where Reader :: Reader e eOne 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.WgGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).XbThe handler of Reader requests. The return type shows that all Reader requests are fully handled.YLocally 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.Z>Request the environment value using a transformation function.UVWXYZUVWXYZUVWYZXUVWXYZ Safe,:OQRT[The 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 e|, the value from the environment. So, the return type is restricted: 'a ~ e' data Reader e v where Reader :: Reader e eOne 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).^bThe handler of Reader requests. The return type shows that all Reader requests are fully handled._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`>Request the environment value using a transformation function.[\]^_`[\]^_`[\]_`^[\]^_` Safe %&,:QRTaDefine 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)ePrimitive state operationsi The handlerjBackwards 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.kAnother 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 abcdefghijk abcdefghijk abcdefghijkabcdefghijk Safe%&,2:QRlTrace effect for debuggingnPrint a string as a trace.oSRun a computation producing Traces. The handler for IO request: a terminal handlerlmnolmnolmnolmnoSafe,:OQRTpThe 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 thenrWrite a new value.s#Transform the state being produced.tjHandle Writer requests, using a user-provided function to accumulate values, hence no Monoid constraints.u:Handle Writer requests, using a List to accumulate values.vEHandle Writer requests, using a Monoid instance to accumulate values.w:Handle Writer requests by taking the first value provided.x6Handle Writer requests by overwriting previous values. pqrstuvwx pqrstuvwx pqrstwxuvpqrstuvwx Trustworthy %&,:OQRT yState, 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).}BReturn the current value of the state. The signatures are inferred~Write a new value of the state.Run a State effect$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  backwardnessyz{|}~Effect incorporating State Initial state0Effect containing final state and a return valueyz|{}~yz{|}~ yz{|}~Safe%&,:QR2Write 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%&:Define data using GADTs.7Then, implements interpreters from the data to effects.Safe,:OQRTThe 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.  Trustworthy %&,:OQRT 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 StateBReturn the current value of the state. The signatures are inferredWrite a new value of the state.Run a State effect$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.Effect incorporating State Initial state0Effect containing final state and a return value  !"#$%&'()*+,-./01234567889:;<==>??@ABBCDEEFGHIIJKLMNOPQRSTUVWXYZ[\]^_ ` ` a b c c d e f g c c d e f g h i j k l m n o p q r s s t uvvwxyz{|}~koqrvvwxyz{|}~0extensible-effects-2.0.0.2-9qY3bFZPhJ78V3Az46BIXData.OpenUnion Control.EffControl.Eff.ChooseControl.Eff.CoroutineControl.Eff.FreshControl.Eff.LiftControl.Eff.ExceptionControl.Eff.NdetEffControl.Eff.OperationalControl.Eff.Reader.LazyControl.Eff.Reader.StrictControl.Eff.State.LazyStateControl.Eff.TraceControl.Eff.Writer.LazyControl.Eff.State.LazyControl.Eff.ExampleControl.Eff.Operational.ExampleControl.Eff.Writer.StrictControl.Eff.State.Strict Data.FTCQueue SetMemberMemberinjprjUniondecompweaken$fMemberU'kFalsetagt:$fMemberU'kTruetagtag:$fSetMemberktagt1: $fEQUBoolkabp$fEQUBoolkaaTrue$fFindElem[]t:$fFindElem[]t:0 $fMembertrEffValEArrsArrarridentsinglefirstcompqAppqCompsendrun handle_relayhandle_relay_s interpose $fMonadEff$fApplicativeEff $fFunctorEffChoosechoosemzero'mplus' makeChoiceYDoneYieldyieldrunCFreshfresh runFresh'LiftliftrunLiftFailExcthrowExcdierunExcrunFailcatchExconFail rethrowExc liftEither liftEitherM liftMaybe liftMaybeM ignoreFailNdetEffMZeroMPlus makeChoiceA0 makeChoiceAmsplitifteonce$fMonadPlusEff$fAlternativeEffProgram singleton runProgramReaderask runReaderlocalreader LazyStateLGetLPutDelaylgetlputlmodifyonDemand runStateLazy runStateBack0 runStateBackTracetracerunTraceWritertellcensor runWriter runListWriterrunMonoidWriterrunFirstWriter runLastWriterStateGetPutgetput runState'runStatemodify evalState execState runStateRMovewriteAllsumAll writeAndAddsumEfflastEff lastAndSumhandUphandDownJailPrintScanprogadventIO adventPure ProxyStatetransactionStateEQUFindElemMemberU'elemNoPunPinj'prj'decomp0ViewLFTCQueue tsingleton|>><TOne:|LeafNodetviewlbaseGHC.BaseNothingJust