;      !"#$%&'()*+,-./0123456 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U VWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ Trustworthy&'+79;>KLN3This class is used for emulating monad transformersThe  impl t r specifies whether t& is present anywhere in the sum type r, where t is some effectful type (e.g. Lift , State Int`$), for a particular implementation (impl label, eg. OU1 representing  OpenUnion1).&A sum data type, for composing effects Parameter r> is phantom: it just tells what could be in the union. Where r is t1 :> t2 ... :> tn,  r v* can be constructed with a value of type ti v4. Ideally, we should be able to add the constraint Member t r.RNOTE: exposing the constructor below allows users to bypass the type system. See  for example.Safe&'(34579>KLLabel to represent  OpenUnion1 implementation For emulating monad transformersInstance MemberImpl is defined only for the sake of the interface compatibility with OpenUnion1. Generally, the closed type family Member' below could be used instead. OU2 t r specifies whether t& is present anywhere in the sum type r, where t is some effectful type  Safe&'>Safe '+34579>KL is similar to V, but it allows types to belong to a "set". For every set, only one member can be in rb at any given time. This allows us to specify exclusivity and uniqueness among arbitrary effects: w-- Terminal effects (effects which must be run last) data Terminal -- Make Lifts part of the Terminal effects set. -- The fundep assures that there can only be one Terminal effect for any r. instance Member (Lift m) r => SetMember Terminal (Lift m) r -- Only allow a single unique Lift effect, by making a "Lift" set. instance Member (Lift m) r => SetMember Lift (Lift m) rfor the sake of gcast1 used below in infix form of  fromMaybe.Construct a Union.7Try extracting the contents of a Union as a given type.jExtract the contents of a Union as a given type. If the Union isn't of that type, a runtime error occurs.Try extracting the contents of a Union as a given type. If we can't, return a reduced Union that excludes the type we just checked. )Juggle types for a Union. Use cautiously.      Safe!"+,;N The traditional view of Free constructions case embedding pure values (case embedding impure values nested in f. Traditionally this is the Control.Monad.Free.Free$ constructor, but that's confusing.8The abstract Free datatype. Original work available at  Ihttp://okmij.org/ftp/Haskell/AlgorithmsH1.html#reflection-without-remorse.cType used to denote monadic chain of binds. As expected this builds on the Kleisli representation.DSpecific type-aligned sequence used to store chain of monadic binds.Inject a pure value into Free Inject an impure value into FreeCase analysis for the $ construction. Similar in spirit to  and .A way to get a U construction from the view by constructing an explicit expression with one element.A way to evaluate the  construction to its view (i.e., head normal form). This includes the logic to perform one level of monadic bind as needed from the  representation.The essence of monadic ', i.e., append/concatenation (of sorts) 'function to be applied if value is Pure&function to be applied on Impure valueFree value to be mapped overresult     Safe 3457;FIKLNEBasic type returned by all computations with extensible effects. The  r' type is a type synonym where the type rC is the type of effects that can be handled, and the missing type aD (from the type application) is the type of value that is returned.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.As is made explicit below, the 3 type is simply the Free monad resulting from the  r functor. type  r a =  ( r) aVGiven a method of turning requests into results, we produce an effectful computation.'Get the result from a pure computation..Given a request, either handle it or relay it.Given a request, either handle it or relay it. Both the handler and the relay can produce the same type of request that was handled.RequestRelay the requestHandle the request of type t  Safe+4;KLNNondeterministic choicefchoose lst non-deterministically chooses one value from the lst choose [] thus corresponds to failure3MonadPlus-like operators are expressible via choose3MonadPlus-like operators are expressible via choose4Run a nondeterministic effect, returning all values.Safe+-4KLStatus 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."The yield request: reporting a value of type e and suspending the coroutine. For readability, a coroutine accepts a unit to produce its value.$2Yield a value of type a and suspend the coroutine.%&Launch a thread and report its status. !"#$% !"#$%"#$% ! !"#$%Safe+-47KL&Strict state effect(Write a new value of the state.)&Return the current value of the state.*$Transform the state with a function.+Run a State effect.,/Run a State effect, discarding the final state.-.Run a State effect and return the final state.&'()*+ Initial stateEffect incorporating State0Effect containing final state and a return value,-&'()*+,-&')(*+,-&'()*+,-Safe+-47KL.DThe request to remember a value of type w in the current environment0Write a new value.1#Transform the state being produced.2LHandle Writer requests, using a user-provided function to accumulate values.3:Handle Writer requests by taking the first value provided.46Handle Writer requests by overwriting previous values.5EHandle Writer requests, using a Monoid instance to accumulate values../012345./012345./012345./012345 Safe462Write the elements of a list of numbers, in order.7+Add a list of numbers to the current state.8:Write a list of numbers and add them to the current state.9Sum 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 list6789:;6789:;6789:;6789:; Safe +3457;KLN<Lift a Monad m to an effect.>Lift a Monad to an Effect.?_The handler of Lift requests. It is meant to be terminal: we only allow a single Lifted Monad.<=>?<=>?<=>?<=>? Safe+-4KL ADThese are exceptions of the type e. This is akin to the error monad.C/Throw an exception in an effectful computation.D?Makes an effect fail, preventing future effects from happening.E2Run a computation that might produce an exception.F<Runs a failable effect, such that failed computation return  , and  the return value on success.GmRun a computation that might produce exceptions, and give it a way to deal with the exceptions that come up.HsAdd a default value (i.e. failure handler) to a fallible computation. This hides the fact that a failure happened.IiRun a computation until it produces an exception, and convert and throw that exception in a new context.J6Treat Lefts as exceptions and Rights as return values.KJ in a lifted MonadLLift a maybe into the @! effect, causing failure if it's .MIgnores a failure event. Since the event can fail, you cannot inspect its return type, because it has none on failure. To inspect it, use F.@ABCDEFGHThe fallible computation."The computation to run on failure.IJKLM@ABCDEFGHIJKLMAB@CDEFGHIJKLM @ABCDEFGHIJKLM Safe+4KLNQThe 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.NOPQNOPQNOQPNOPQ Safe+-47KLR Create unique Enumerable values.T6Produce a value that has not been previously produced.U&Run an effect requiring unique values.RSTURSTURSTURSTUSafe+-47KLVxThe request for a value of type e from the current environment. This environment is analogous to a parameter of type e.X$Get the current value from a Reader.YnLocally rebind the value in the dynamic environment. This function both requests and handles Reader requests.Z>Request the environment value using a transformation function.[bThe handler of Reader requests. The return type shows that all Reader requests are fully handled.VWXYZ[VWXYZ[VWXYZ[VWXYZ[Safe+-47KL\xThe request for a value of type e from the current environment. This environment is analogous to a parameter of type e.^$Get the current value from a Reader._mLocally rebind the value in the dynamic environment. This function both requests and admins Reader requests.`>Request the environment value using a transformation function.abThe handler of Reader requests. The return type shows that all Reader requests are fully handled.\]^_`a\]^_`a\]^_`a\]^_`aSafe+-47KLbStrict state effectdWrite a new value of the state.e&Return the current value of the state.f$Transform the state with a function.gRun a State effect.h/Run a State effect, discarding the final state.i.Run a State effect and return the final state.bcdefg Initial stateEffect incorporating State0Effect containing final state and a return valuehibcdefghibcedfghibcdefghiSafe+-47KLjDThe request to remember a value of type w in the current environmentlWrite a new value.m#Transform the state being produced.nLHandle Writer requests, using a user-provided function to accumulate values.o:Handle Writer requests by taking the first value provided.p6Handle Writer requests by overwriting previous values.qEHandle Writer requests, using a Monoid instance to accumulate values.jklmnopqjklmnopqjklmnopqjklmnopqSafe+-4KLrTrace effect for debuggingtPrint a string as a trace.u#Run a computation producing Traces.rsturstursturstuSafe +47;IKLNvELift values to an effect. You can think this is a generalization of Lift.xLift a value to a monad.y2Convert values using given interpreter to effects.vwxyvwxyvwxyvwxySafe!"+4zDefine data using GADTs.~7Then, implements interpreters from the data to effects.z{|}~z{|}~z{|}~z{|}~ !"#$%&'()*+,-./0012345567789::;<=>?@AABCDEFG H I J K L M N N O P Q R R S T U V W X Y Z [ \ ] ^ ^ _ ` a a b cddefghddefgh::;<=>?@AABCDEFGiijkllmnopqrstuvwxyz{|}~% exten_4WFeOypyNBz0p2ld1ErUSrData.OpenUnionData.OpenUnion.ImportsControl.Monad.Free.Reflection Control.EffControl.Eff.ChooseControl.Eff.CoroutineControl.Eff.State.LazyControl.Eff.Writer.LazyControl.Eff.ExampleControl.Eff.LiftControl.Eff.ExceptionControl.Eff.CutControl.Eff.FreshControl.Eff.Reader.LazyControl.Eff.Reader.StrictControl.Eff.State.StrictControl.Eff.Writer.StrictControl.Eff.TraceControl.Eff.OperationalControl.Eff.Operational.ExampleData.OpenUnion.Internal.Base unsafeReUnion"Data.OpenUnion.Internal.OpenUnion2:>UnionMemberUMember SetMemberinjprjprjForcedecompweakenFreeViewPureImpureFreefreePure freeImpurefreeMapfromViewtoViewEffsendrun handleRelay interposeChoosechoosemzero'mplus' runChoiceYDoneYieldyieldrunCStateputgetmodifyrunState evalState execStateWritertellcensor runWriterrunFirstWriter runLastWriterrunMonoidWriterwriteAllsumAll writeAndAddsumEfflastEff lastAndSumLiftliftrunLiftFailExcthrowExcdierunExcrunFailcatchExconFail rethrowExc liftEither liftEitherM liftMaybe ignoreFailCutFalsecutfalsecallFreshfreshrunFreshReaderasklocalreader runReaderTracetracerunTraceProgram singleton runProgramJailPrintScanprogadventIO adventPure MemberUImpl MemberImplghc-prim GHC.TypesIOMemberUConstraintMemberConstraint$fFunctorUnionOU2TFCo:R:MemberUConstraintOU2trTFCo:R:MemberConstraintOU2trMemberU'EQUMember'$fMemberU'kFalsetagt:>$fMemberU'kTruetagtag:>$fMemberUImplkOU2tagt1:>$fMemberImplOU2trbaseGHC.Base<*>pure Applicative<**>IdrunId$fSetMember(->)settrFreeExpTCQ Data.Eithereither Data.Maybemaybe^>>=>>= $fMonadFree$fApplicativeFree $fFunctorFree$fFunctorChoose$fMonadBasebFree $fMonadIOFree $fFunctorLiftNothingJust$fFunctorProgram