Îõ³h$.Ò+በ     !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ2Internal module for type-safe multi-prompt control7(c) 2020, Microsoft Research; Daan Leijen; Ningning XieMIT!xnning@hku.hk; daan@microsoft.com ExperimentalNone'(ÆÙ† eveff2The Multi Prompt control monad, with existentials ans and b: where ansÆ is the answer type, i.e. the type of the handler/prompt context, and b" the result type of the operation.eveff+Pure results (only exported for use in the Control.Ev.Eff module)eveffAn abstract prompt markereveff3Compare two markers of different types for equalityeveff yield m op' yields to a specific marker and calls op in that context with a  resumption k :: b -> Ctl ans? that resumes at the original call-site with a result of type bâ. If the marker is no longer in the evaluation context, (i.e. it escaped outside its prompt) the  fails with an "unhandled operation" error.eveff Install a prompt with a specific prompt  to which one can ß. This connects creation of a marker with instantiating the prompt. The marker passed to the action argument should not escape the action< (but this is not statically checked, only at runtime when  ing to it).eveff+Run a control monad. This may fail with an "unhandled operation" error if there is a + to a marker that escaped its prompt scope.eveffUnsafe ‰ in the  monad.eveff Create an Š* connected to a prompt. The value of the Š+ is saved and restored through resumptions.  7Efficient effect handlers based on Evidence translation7(c) 2020, Microsoft Research; Daan Leijen; Ningning XieMIT!xnning@hku.hk; daan@microsoft.com ExperimentalNone'(-/>?ÀÁÂÄÉÔÖ×Ù#UeveffŒThe type of the built-in state effect. (This state is generally more efficient than rolling your own and usually used in combination with &! to provide local isolated state)eveff(The abstract type of operations of type a to b., for a handler defined in an effect context e and answer type ans.eveff!An effect membership constraint: h :? e! ensures that the effect handler h is in the effect context e. For example: inc :: (State Int  e) =>  e () inc = do i <-  get ()  put (i+1) } eveff&The effect monad in an effect context e with result aeveffÛAn effect context is a type-level list of effects. A concrete effect context has the form (h1 :* h2 :* ... :* hn :* ())0. An effect context can also be polymorpic, as (h :* e), denoting a top handler h with a tail e. For example the type of ! reflects that in an expression ( hnd action) that the action can perform operations in h; as that is now the top handler in the effect context for action:  :: h e ans ->  (h  e) ans ->  e ans É(Note: The effects in a context are partially applied types -- an effect h e ansÊ denotes a full effect handler (as a value) defined in an effect context e and with answer type ansÛ. In the effect context type though, these types are abstract and we use the partial type h do denote the effect)eveffUse handler hnd action to handle effect h with handler hnd in action (which has h in its effect context now as h :* e). For example: &data Reader a e ans = Reader { ask ::  () a e ans } reader :: a ->  (Reader a  e) ans ->  e ans reader x =  (Reader{ ask =  x }) eveffËRun an effect monad in an empty context (as all effects need to be handled)eveffHandle an effect h over action) and tranform the final result with the return function ret. For example: 7data Except a e ans = Except { throwError :: forall b.  a b e ans } exceptMaybe ::  (Except a  e) ans ->  e (Maybe ans) exceptMaybe = = Just (Except{ throwError = except (\_ -> return Nothing) }) eveffDefine a handler h that hides the top handler h' from its action, while keeping h'2 is still visible in the operation definitions of h8. This is used to implement locally isolated state for & using the regular $ state. In particular, & is implemented as: & :: a -> (h ( a  e) ans) ->  (h  e) ans ->  e ans & init h action = $ init ( h action) eveffØMask the top effect handler in the give action (i.e. if a operation is performed on an h effect inside e the top handler is ignored).eveff•Given an operation selector, perform the operation. The type of the selector function is a bit intimidating, but it just selects the right operation  from the handler h" regardless of the effect context e' and answer type ans where the handler is defined.ßUsually the operation selector is a field in the data type for the effect handler. For example: %data Reader a e ans = Reader{ ask :: ' () a e ans } greet :: (Reader String  e) =>  e String greet = do s <-  ask () ‹ ("hello " ++ s) test =  $  (Reader{ ask =  "world" }) $ greet eveffÇCreate an operation that always resumes with a constant value (of type a). (see also the  example).eveff3Create an operation that takes an argument of type a* and always resumes with a result of type b. These are called tail-resumptiveÜ operations and are implemented more efficient than general operations as they can execute in-placeÛ (instead of yielding to the handler). Most operations are tail-resumptive. (See also the & example).eveff,Create an fully general operation from type a to b. the function f takes the argument, and a  resumption function of type b ->  e ansÈ that can be called to resume from the original call site. For example: )data Amb e ans = Amb { flip :: forall b.  () Bool e ans } xor :: (Amb  e) =>  e Bool xor = do x <-  flip () y <- Æ flip () return ((x && not y) || (not x && y)) solutions ::  (Amb  e) a ->  e [a] solutions = ' (\x -> [x]) $ Amb{ flip = Ä (\() k -> do{ xs <- k True; ys <- k False; return (xs ++ ys)) }) } eveff=Create an operation that never resumes (an exception). (See  for an example).eveff!Get the value of the local state.eveff!Set the value of the local state.eveff$Update the value of the local state. eveff:Get the value of the local state if it is the top handler.!eveff:Set the value of the local state if it is the top handler."eveff=Update the value of the local state if it is the top handler.#eveff;Create a local state handler with an initial state of type aÞ, with a return function to combine the final result with the final state to a value of type b.$eveff;Create a local state handler with an initial state of type a.%eveffCreate a new handler for h which can access the locally isolated state  a&. This is fully local to the handler h only and not visible in the action2 as apparent from its effect context (which does not contain  a). The retÒ argument can be used to transform the final result combined with the final state.&eveffCreate a new handler for h which can access the locally isolated state  a&. This is fully local to the handler h only and not visible in the action2 as apparent from its effect context (which does not contain  a). $data State a e ans = State { get ::  () a e ans, put ::  a () e ans } state :: a ->  (State a  e) ans ->  e ans state init = & init (State{ get =  (\_ ->  3 ()), put =  (\x ->   x) }) test = = $ state (41::Int) $ inc -- see   !"#$%&$#&% !"5$Definitions for some common effects.7(c) 2020, Microsoft Research; Daan Leijen; Ningning XieMIT!xnning@hku.hk; daan@microsoft.com ExperimentalNone >?ÀÁÂÔÖ×Ù*4.eveffChoose implements backtracking.0eveff&@`perform none ()` indicates no result1eveff choose n` resumes up to n times (returning 1 up to n@)2eveff5A standard exception effect, throwing values of type a.4eveff(Throw an exception with a value of type a (as  throwError x)5eveff!A standard writer effect of type a7eveffOutput a value of type a (as  tell msg)8eveff A standard state effect of type a.:eveffGet the current state (as  get ());eveffSet the current state (as  put x)<eveff,A standard reader effect for values of type a.>eveffget the reader value of type a (as  ask ())?eveffA handler for a < effect with a value of type a.@eveff4A state handler that takes an initial state of type a.Aeveff A standard 5 handler for any monoidal type a$. Returns the final result of type ans and the appended tell arguments.BeveffHandle an exception.Ceveff$Transform an exception effect to an Either type.DeveffÒRemove the exception effect using a default value in case an exception was thrown.Eeveff#Transform an exception effect to a Maybe type.Geveff5Return the first result found in a computation using 1 for backtracking.Heveff9Return all possible results found in a computation using 1 for backtracking./0123456789:;<=>?@ABCDEFGH<=>?89:;@567A234BCED./01FGHExamples of Control.Ev.Eff7(c) 2020, Microsoft Research; Daan Leijen; Ningning XieMIT!xnning@hku.hk; daan@microsoft.com ExperimentalNone?ÔÖ×Ù+>KLMNOPQRSTUVWXZY[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ>^_`abcdefg[\]hijklmWXZYnopqrTUVsQRStuvwxyz{NOP|}~€‚ƒ„…KLM†‡ˆ Safe-Inferred+ÌŒŽ‘’“”      !"#$%&'()*+,-./0123445677899:;;<=>>?@ABCDEFGHIJKLLMNNOPPQRRS;;<=TTU>>?V@WXYZ[\]E^_`Aabcdefghijklmnopqrstuvwxyz{|}~€~‚ƒ„…†‡ˆ‰Š‹$eveff-1.0.0.2-9XUHFMCFC8iEl6DtUgCtaQControl.Ev.CtlControl.Ev.EffControl.Ev.UtilExamples Paths_eveffCtlPureMarkermarkerEqyieldpromptrunCtlunsafeIOunsafePromptIORef $fEqMarker $fShowMarker $fMonadCtl$fApplicativeCtl $fFunctorCtlLocalOp:?Eff:*handlerrunEff handlerRet handlerHidemaskperformvaluefunction operationexceptlgetlputlmodifylocalGetlocalPut localModifylocalRetlocalhandlerLocalRet handlerLocal $fEqContext $fMonadEff$fApplicativeEff $fFunctorEff$fInEqFalsehh'e$fInEqTruehh'e$fInh:*ChoosenonechooseExcept throwErrorWritertellStategetputReaderaskreaderstatewriter catchError exceptEither exceptDefault exceptMaybenone' chooseFirst chooseAll$fMonadPlusEff$fAlternativeEffEvilevilParsesatisfyAmbflipOutputoutExnfailurehrsample1 greetOrExit greetMaybegreet helloWorldfailure'toMaybesafeDivsafeHeadsample3addinverttestadderoutputxor allResults firstResult solutionseagerchoicemanymany1satisfy'parsesymboldigitexprtermfactornumbertest1test2hevilebody nonscopedghc-prim GHC.TypesIObase GHC.IORefIORefGHC.Basereturnversion getBinDir getLibDir getDynLibDir getDataDir getLibexecDir getSysconfDirgetDataFileName