úÎ, ½      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVW X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q rstu v w x y z { | } ~  € ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ Ž ‘ ’ “ ”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼Safe&',-;<=>?FQSTV½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&'+,-;<=>?AFQSTV$Ò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+A useful operator for reducing boilerplate. 9f :: [Reader Int, Writer String] ::> r => a -> Eff r b  is equal to If :: (Member (Reader Int) r, Member (Writer String) r) => a -> Eff r b /The data constructors of Union are not 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 wExplicit type-level equality condition is a dirty hack to eliminate the type annotation in the trivial case, such as run (runReader get ()).2There is no ambiguity when finding instances for Member t (a ': b ': r)(, which the second instance is selected.-The only case we have to concerned about is  Member t '[s]À. But, in this case, values of definition is the same (if present), and the first one is chosen according to GHC User Manual, since the latter one is incoherent. This is the optimal choice. ÉÊËÌÍÎ Trustworthy&',-;<=>?FNQSTVN?%Lifting: emulating monad transformersÏ\The Eff monad (not a transformer!). It is a fairly standard coroutine monad where the type rC is the type of effects that can be handled, and the missing type a (from the type application) is the type of value that is returned. It is NOT a Free monad! There are no Functor constraints.ÂThe two constructors denote the status of a coroutine (client): done with the value of type a, or sending a request of type Union r with the continuation Arrs r b a. Expressed another way: an Ï can either be a value (i.e., Ð case), or an effect of type  r producing another Ï (i.e., Ñ case). The result is that an Ï+ can produce an arbitrarily long chain of  r' effects, terminated with a pure value. Potentially, inline Union into EÒAn 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 rÔCconvert 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 arrowØThe identity arrowÙArrow compositionÚCommon 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)âEmbeds a less-constrained Ï2 into a more-constrained one. Analogous to MTL's .4We make the Lift layer to be unique, using SetMember_The handler of Lift requests. It is meant to be terminal: we only allow a single Lifted Monad.ãbEff is still a monad and a functor (and Applicative) (despite the lack of the Functor constraint)äAs the name suggests, Ò also has an Arrow instance.åÒ- can be composed and have a natural identity.ÏÑÐÒæÓçÔÕÖרÙÚÛÜÝÞßàáâÏÐÑÒæSafe&',-;<=>?FQSTVYó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 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.  Safe&',-;<=>?FQSTVeh 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.':Handle Writer requests by taking the first value provided.(6Handle Writer requests by overwriting previous values. !"#$%&'( !"#$'(%& !Safe&',-;<=>?FQSTVvœ*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 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.,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.*+,-./*+,./-*+ Trustworthy&',-;<=>?FQSTVŠ^ 1‹An encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfully3 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 State6BReturn the current value of the state. The signatures are inferred7Write a new value of the state.9Run 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.9Effect incorporating State Initial state0Effect containing final state and a return value123546789:;<=>345?6789:;<12=>12345Safe&',-;<=>?FQSTV›Ç@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 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.BgGet the current value from a Reader. The signature is inferred (when using NoMonomorphismRestriction).CbThe handler of Reader requests. The return type shows that all Reader requests are fully handled.D•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.E>Request the environment value using a transformation function.@ABCDE@ABDEC@A Trustworthy&',-;<=>?FQSTV´ƒ GState, 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).KBReturn the current value of the state. The signatures are inferredLWrite a new value of the state.ORun a State effectP$Transform the state with a function.Q/Run a State effect, discarding the final state.R.Run a State effect and return the final state.SÓ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.Tõ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.UA 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  backwardnessOEffect incorporating State Initial state0Effect containing final state and a return valueGJIHKLMNOPQRSTUGHIJVKLMNOPQRSTUGHIJ  Trustworthy&',-;<=>?FQSTVȉ W‹An encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfullyY State, lazy³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 State\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.a/Run a State effect, discarding the final state.b.Run a State effect and return the final state.dÓ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 valueWXY[Z\]^_`abcdYZ[e\]^_`abWXcdWXYZ[ Safe&',-;<=>?FQSTVÒCfIA different implementation, more directly mapping to MonadPlus interfaceiº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 emptyj°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.k_Same as makeChoiceA, except it has the type hardcoded. Required for MonadBaseControl instance. fhgijklmn fghqpoijklmnfghSafe&'+,-;<=>?FQSTVÖ–rSame as s but with additional è constraints1A convenient alias to 'SetMember Lift (Lift m) r't4Catching of dynamic exceptions See the problem in 4http://okmij.org/ftp/Haskell/misc.html#catch-MonadIOrstsrt Safe&',-3;<=>?FQSTVÙ¦u Create unique Enumerable values.w6Produce a value that has not been previously produced.x&Run an effect requiring unique values.uvwxuvwxuvé Safe&',-;<=>?FQSTVîi{ Exceptions'exceptions of the type e; no resumption}EThrow an exception in an effectful computation. The type is inferred.~£Throw an exception in an effectful computation. The type is unit, which suppresses the ghc-mod warning "A do-notation statement discarded a result of type"?Makes an effect fail, preventing future effects from happening.€2Run a computation that might produce an exception.<Runs a failable effect, such that failed computation return ê , and ë the return value on success.‚žRun a computation that might produce exceptions, and give it a way to deal with the exceptions that come up. The handler is allowed to rethrow the 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 z! 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.z{|}~€‚ƒ„…†‡ˆ‰{|z}~€‚ƒ„…†‡ˆ‰{| Safe&',-;<=>?FQSTVù‹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 choose3MonadPlus-like operators are expressible via choose4Run a nondeterministic effect, returning all values.’3MonadPlus-like operators are expressible via choose‹ŒŽ‹ŒŽ‹ŒSafe&',-;<=>?FQSTVù÷ÏÑÐÒæÓçÔÕÖרÙÚÛÜÝÞßàáâSafe&',-3;<=>?FQSTVýc”Trace effect for debugging–Print a string as a trace.—SRun a computation producing Traces. The handler for IO request: a terminal handler”•–—”•–—”•Safe&',-;<=>?CFQSTVØELift values to an effect. You can think this is a generalization of Lift.šLift a value to a monad.›2Convert values using given interpreter to effects.˜™š›˜™š›˜™Safe&',-;<=>?FQSTVøœDefine data using GADTs. 7Then, implements interpreters from the data to effects.œžŸ ¡œžŸ ¡œžSafe&'+,-;<=>?FQSTV Q ¤JThe datatype for the example from the paper. See the tests for the example¦0specialization to tell the type of the exception§Multiple Reader effects¨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&',-;<=>?FQSTV;µí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²³´µ²³´µ²³Safe&',-3;<=>?FQSTVɶ€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¶·¸¹º»¼¹º»¼¶·¸¶·¸¹ºì !"#$%&'())*+,-./012345,-./0123456789:;5<<=>?@ABCDEFGH56789:;5I>?J@AKBCDEFHLM5 < < = > ? @ A B C D E F G H 5 N O P Q R S T U V 5 W XYZ[ \ \ ] ^ 5 _ ` ` a b c d e f g h i j k l m 5 n n o p q r W X 5sstuvwxyz{|}~€€‚ƒ„…†‡ˆ‰Š‹ŒŽŽ‘‘’““”•–—˜™š›œžŸ ¡¢£¤¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼©½¾¿À ÁÂÃÄÂÃÅÆ1extensible-effects-2.5.3.0-B2kdXPKYMsc3GMO4ZfzL0pData.OpenUnionControl.Eff.LiftControl.Eff.Writer.StrictControl.Eff.Writer.LazyControl.Eff.Reader.StrictControl.Eff.State.StrictControl.Eff.Reader.LazyControl.Eff.State.OnDemandControl.Eff.State.LazyControl.Eff.NdetEffControl.Eff.FreshControl.Eff.ExceptionControl.Eff.ChooseControl.Eff.TraceControl.Eff.OperationalControl.Eff.Operational.ExampleControl.Eff.ExampleControl.Eff.CutControl.Eff.Coroutine Data.FTCQueueControl.Eff.Internal Control.Eff SetMember<::MemberinjprjUniondecompweaken$fFindElem[]t[]$fFindElem[]t:$fFindElem[]t:0 $fMembertr $fMembert: $fEQUkBoolabp$fEQUkBoolaaTrue$fMemberU'kFalsetagt:$fMemberU'kTruetagtag:$fSetMemberktagt1:LiftliftrunLiftWriterTelltellcensor runWriter runListWriterrunMonoidWriterrunFirstWriter runLastWriter$fMonadBaseControlmEffReaderAskask runReaderlocalreaderTxStateStateGetPutgetput runState'runStatemodify evalState execStatetransactionState runStateR OnDemandStateDelayonDemand runStateBack0 runStateBackNdetEffMZeroMPlus makeChoiceA0 makeChoiceA makeChoiceLstmsplitifteonce$fMonadPlusEff$fAlternativeEff LiftedBaseLifted catchDynEFreshfresh runFresh'FailExc throwError throwError_dierunErrorrunFail catchErroronFail rethrowError liftEither liftEitherM liftMaybe liftMaybeM ignoreFailChoosechoosemzero'mplus' makeChoiceTracetracerunTraceProgram Singleton singleton runProgramJailPrintScanprogadventIO adventPureMoveTooBig runErrBigsum2writeAllsumAll writeAndAddsumEfflastEff lastAndSumhandUphandDown $fEqTooBig $fShowTooBigCutFalsecutfalsecallYDoneYieldyieldrunCViewLFTCQueue tsingleton|>><viewlMaptviewlTOne:|LeafNodeEQUFindElemelemNoPunPEffValEArrsArrsingleKqApp^$arridentcomp^|>qCompqCompssendrun handle_relayhandle_relay_s interposeraise $fFunctorEff $fArrowArrs$fCategoryTYPEArrsfirst,monad-control-1.0.2.3-Hydp52czSVm8SDKsQHQ2k2Control.Monad.Trans.ControlMonadBaseControlReplacebaseGHC.BaseNothingJust