úÎçõÛ½­      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬ghcbeta"Neil Sculthorpe <neil@ittc.ku.edu> Safe-Inferred*­s with failure and catching. * The following law is expected to hold:  failT msg `catchT` f == f msg  The failing ­.  A catch on ­s. ®s with a catch for ¯. * The following law is expected to hold:  fail msg `catchM` f == f msg %Catch a failing monadic computation. 0A monadic catch that ignores the error message. OSelect the first monadic computation that succeeds, discarding any thereafter. NCatch a failing monadic computation, making it succeed with a constant value. <Catch a failing monadic computation, making it succeed with °. NCatch a failing monadic computation, making it succeed with an error message. -Determine if a monadic computation succeeds.  Fail if the ® succeeds; succeed with () if it fails. ;Modify the error message of a failing monadic computation. + Successful computations are unaffected. 8Set the error message of a failing monadic computation. + Successful computations are unaffected. DAdd a prefix to the error message of a failing monadic computation. + Successful computations are unaffected. MUse the given error message whenever a monadic pattern match failure occurs.  Similar to ±, but invokes ¯ rather than ². As $, but with a default error message. .if-then-else lifted over a monadic predicate. KIf the monadic predicate holds then perform the monadic action, else fail. KIf the monadic predicate holds then fail, else perform the monadic action. Left-biased choice. Look at the argument to the ³ before choosing which ³ to use. Look at the argument to an ³;, and choose to be either the identity arrow or a failure. Look at the argument to an ³;, and choose to be either the identity arrow or a failure.  This is a generalisation of  to any ³. Catch a failing , making it into an identity. Catch a failing ³), making it succeed with a Boolean flag.  Useful when defining  instances.  Makes an ³5 fail if the result value equals the argument value.  Repeat a < until it fails, then return the result before the failure. 3 Requires at least the first attempt to succeed.  Attempt two ³2s in sequence, succeeding if one or both succeed. Sequence a list of ³s, succeeding if any succeed. Sequence a list of ­s, succeeding if all succeed. Select the first + that succeeds, discarding any thereafter. !*Apply a pure function to the result of an ³. ",Apply a pure function to the argument to an ³. # Apply an ³@ to the first element of a pair, discarding the second element. $ Apply an ³@ to the second element of a pair, discarding the first element. %A pure ³$ that swaps the elements of a pair. &A pure ³ that duplicates its argument. 'Tag the result of an ³ with its argument. (Tag the result of an ³ with its argument. )!An arrow with a constant result. *  !"#$%&'()*  !"#$%&'()*  !"#$%&'()'  !"#$%&'()ghcbeta"Neil Sculthorpe <neil@ittc.ku.edu> Safe-Inferred)*A *. is a way to focus on a sub-structure of type b from a structure of type a. + Convert a * into a 1N that produces a sub-structure (and its context) and an unfocussing function. ,A -. that shares the same source and target type. -An undirected 1. .Extract the foreward 1 from a -. /Extract the backward 1 from a -. 0A 1. that shares the same source and target type. 1DAn abstract representation of a transformation from a value of type a in a context c to a monadic value of type m b.  The 1/ type is the basis of the entire KURE library. 2Apply a 1 to a value and its context. 3!The primitive way of building a 1. 4 The primitive way of building a 0. 5Build a 1 that doesn't depend on the context. 6Build a 1 that doesn't depend on the value. 7Build a constant 1 from a monadic computation. 8Extract the current context. 9&Expose the current context and value. :Map a 1 over a list. ; An identity 0 with side-effects. < Construct a - from two opposite 1s. =Try the ,* forewards, then backwards if that fails. ^ Useful when you know which rule you want to apply, but not which direction to apply it in. >3Invert the forewards and backwards directions of a -. ? The primitive way of building a *. [ If the unfocussing function is applied to the value focussed on then it should succeed, @ and produce the same value as the original argument (of type a). @Apply a 0 at a point specified by a *. AApply a 1 at a point specified by a *. BlCheck if the focusing succeeds, and additionally whether unfocussing from an unchanged value would succeed. C Construct a * from a -. D Construct a * from two pure functions. ´A *[ is deemed to have failed (and thus can be caught) if either it fails on the way down, or, { crucially, if it would fail on the way up for an unmodified value. However, actual failure on the way up is not caught 4 (as by then it is too late to use an alternative *)). This means that, in theory, a use of catch could cause a succeeding * application to fail.  But provided ?. is used correctly, this should never happen. µLifting through the ®E and a Reader transformer, where (c,a) is the read-only environment. ¶The · ³ induced by m., lifting through a Reader transformer, where c is the read-only environment. ¸The · ³ induced by m., lifting through a Reader transformer, where c is the read-only environment. ¹The · ³ induced by m., lifting through a Reader transformer, where c is the read-only environment. ºThe · ³ induced by m., lifting through a Reader transformer, where c is the read-only environment. »The · ­ induced by m., lifting through a Reader transformer, where c is the read-only environment. ¼The · ­ induced by m., lifting through a Reader transformer, where c is the read-only environment. ½PLifting through a Reader transformer, where (c,a) is the read-only environment. ¾PLifting through a Reader transformer, where (c,a) is the read-only environment. ¿PLifting through a Reader transformer, where (c,a) is the read-only environment. ÀPLifting through a Reader transformer, where (c,a) is the read-only environment. ÁPLifting through a Reader transformer, where (c,a) is the read-only environment. ÂPLifting through a Reader transformer, where (c,a) is the read-only environment. .*Ã+,-Ä./01Å23456789:;<=>?@ABCD´ÆÇµ¶¸¹º»¼½¾¿ÀÁÂ*+,-./0123456789:;<=>?@ABCD12023456789:;-./,<./=>*+?+@ABCD'*Ã+,-Ä./01Å23456789:;<=>?@ABCD´ÆÇµ¶¸¹º»¼½¾¿ÀÁÂghcbeta"Neil Sculthorpe <neil@ittc.ku.edu> Safe-InferredE$A class of injective functions from a to b, and their retractions. * The following law is expected to hold:  retract (inject a) == Just a H$Injects a value and lifts it into a ®. I%Retracts a value and lifts it into a #, with the possibility of failure. JLifted F. KLifted G, the 1 fails if the retraction fails. L Convert a 1 over an injected value into a 1 over a non-injected value. MAs N>, but takes a custom error message to use if promotion fails. N Promote a 1 over a value into a 1" over an injection of that value, 9 (failing if that injected value cannot be retracted). OAs P?, but takes a custom error message to use if extraction fails. P Convert a 0 over an injected value into a 0" over a retraction of that value, 9 (failing if that injected value cannot be retracted). QAs R>, but takes a custom error message to use if promotion fails. R Promote a 0 into over a value into a 0" over an injection of that value, 9 (failing if that injected value cannot be retracted). SA * to the injection of a value. TA * to the retraction of a value. È.There is an identity injection for all types. EFGHIJKLMNOPQRSTÉÈEFGHIJKLMNOPQRSTEFGHIJKLNMPROQSTEFGHIJKLMNOPQRSTÉÈghcbeta"Neil Sculthorpe <neil@ittc.ku.edu> Safe-Inferred8U8A path is a route to descend the tree from an arbitrary `. VContexts that are instances of V contain the current X. + Any user-defined combinators (typically Z/ and congruence combinators) should update the X using |. WFind the current path. XA path from the root. YY- captures the ability to walk over a tree of `s,  using a specific context c and a  m. Minimal complete definition: Z. %Default definitions are provided for [, \, ], ^ and _-, but they may be overridden for efficiency. ` For small numbers of interesting children this will not be an issue, but for a large number, * say for a list of children, it may be. Z Construct a * to the n-th child `. [Apply a a 1< to all immediate children, succeeding if they all succeed. ! The results are combined in a Ê. \Apply a a 18 to the first immediate child for which it can succeed. ]Apply a a 0< to all immediate children, succeeding if they all succeed. ^Apply a a 06 to all immediate children, suceeding if any succeed. _Apply a a 08 to the first immediate child for which it can succeed. `A `? is any node in the tree that you wish to be able to traverse. aa> is a sum of all the types of the sub-nodes, transitively, of a.  We use  Generic a ~ a/ to signify that something is its own Generic. 1 Simple expression types might be their own sole a, more complex examples " will have a new datatype for the a*, which will also be an instance of class `. b$Count the number of immediate child `s. cLifted version of b. d Check if a `% has a child of the specified index. eLifted version of d. fApply a 1 to a specified child. gApply a 0 to a specified child. h1Fold a tree in a top-down manner, using a single 1 for each `. i2Fold a tree in a bottom-up manner, using a single 1 for each `. jApply a 1 to the first `4 for which it can succeed, in a top-down traversal. kApply a 1 to the first `5 for which it can succeed, in a bottom-up traversal. lAttempt to apply a 1- in a top-down manner, pruning at successes. m<An always successful top-down fold, replacing failures with °. n=An always successful bottom-up fold, replacing failures with °. o]An always successful traversal that collects the results of all successful applications of a 1 in a list. pLike o), but does not traverse below successes. qApply a 07 in a top-down manner, succeeding if they all succeed. rApply a 08 in a bottom-up manner, succeeding if they all succeed. sApply a 0J twice, in a top-down and bottom-up way, using one single tree traversal, # succeeding if they all succeed. tApply a 02 in a top-down manner, succeeding if any succeed. uApply a 03 in a bottom-up manner, succeeding if any succeed. vApply a 0J twice, in a top-down and bottom-up way, using one single tree traversal,  succeeding if any succeed. wApply a 0 to the first `4 for which it can succeed, in a top-down traversal. xApply a 0 to the first `5 for which it can succeed, in a bottom-up traversal. yAttempt to apply a 07 in a top-down manner, pruning at successful rewrites. z:A fixed-point traveral, starting with the innermost term. { The (empty) X to the root. | Extend an X by one descent. } Find the X to the current `. ~ Convert an X into a U starting at the root.  Find the U s to every ` that satisfies the predicate. € Find the U to the first `: that satisfies the predicate (in a pre-order traversal).  Find the U to the first descendent `: that satisfies the predicate (in a pre-order traversal). ‚ Find the U s to every `( that satisfies the predicate, ignoring `s below successes. ƒ Find the U to the `L that satisfies the predicate, failing if that does not uniquely identify a `. „Build a U to the `L that satisfies the predicate, failing if that does not uniquely identify a ` (ignoring `s below successes). … Construct a * by following a U. † Construct a * that points to the last ` at which the U can be followed. ‡!Repeat as many iterations of the U as possible. ˆBuild a ** from the root to a point specified by an X. ‰Apply a 0 at a point specified by a U. ŠApply a 1 at a point specified by a U. ‹'Check if it is possible to construct a *" along this path from the current `. ËThe simplest instance of V is X itself. ?UVWXÌYZ[\]^_`abcdefgÍÎhijklmnopqrstuvwxyz{|}~ÏЀ‚у„…†‡ˆ‰Š‹ËÒ7UVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹7`abcdeYZ[\]^_gqrstuvwxyzfhijklmnopX{|VW}U~€‚ƒ„…†‡ˆ‰Š‹5UVWXÌYZ[\]^_`abcdefgÍÎhijklmnopqrstuvwxyz{|}~ÏЀ‚у„…†‡ˆ‰Š‹ËÒghcbeta"Neil Sculthorpe <neil@ittc.ku.edu> Safe-InferredŒŒ is a basic error ®. ' The KURE user is free to either use Œ or provide their own monad.  Œ is essentially the same as (Ó Ô a), except that the ¯( method produces an error in the monad,  rather than invoking Õ. W A major advantage of this is that monadic pattern match failures are caught safely. Eliminator for Œ. ŽGet the value from a Œ1, providing a function to handle the error case. šReturn the monadic result of a 1 and pair it with the argument.  DA standard error message for when the child index is out of bounds. ÖŒ1 is the minimal monad that can be an instance of . ;×ØÙŒÚÛŽ‘’“”ÜÝÞßà•–—˜™šáâã䛜žŸ ¡¢£¤¥¦§¨©ª«¬åæçèéêëìíîÖï!ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬!ŒŽ ‘’“”•–—˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬7×ØÙŒÛÚŽ‘’“”ÜÝÞßà•–—˜™šáâã䛜žŸ ¡¢£¤¥¦§¨©ª«¬åæçèéêëìíîÖïghcbeta"Neil Sculthorpe <neil@ittc.ku.edu> Safe-Inferred|  !"#$%&'()*+,-./0123456789:;<=>?@ABCDUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ð      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶´·¸´·¹´º»´¼½´¼¾´¿ÀÁÂô¿ÄÅÆÇÈÉÊËÌÍÎÏ259ÐÑÒÓ´ºÔÕ`ÖרÙÚÛ´ÜÝ´·Þ´ßàáââãäåæçèéêëìíîïðñòóôõö÷øùú kure-2.4.10Language.KURE.CombinatorsLanguage.KURE.TranslateLanguage.KURE.InjectionLanguage.KURE.WalkerLanguage.KURE.UtilitiesanyR Language.KURE CategoryCatchfailTcatchT MonadCatchcatchM<<+catchesMtryMmtryMattemptMtestMnotM modFailMsg setFailMsg prefixFailMsgwithPatFailMsgguardMsgguardMifMwhenMunlessM<+readerTacceptR accepterRtryRattemptRchangedRrepeatR>+>orRandRcatchesTresultargumenttoFsttoSndswapfork forkFirst forkSecondconstantLenslensT BiRewrite BiTranslate forewardT backwardTRewrite Translateapply translaterewrite contextfreeT contextonlyTconstTcontextTexposeTmapT sideEffectR bidirectional whicheverRinvertlensfocusRfocusT testLensTbidirectionalLpureL InjectioninjectretractinjectMretractMinjectTretractTextractTpromoteWithFailMsgTpromoteTextractWithFailMsgRextractRpromoteWithFailMsgRpromoteRinjectLretractLPath PathContext contextPath AbsolutePathWalkerchildLallToneTallRoneRNodeGeneric numChildren numChildrenThasChild hasChildTchildTchildRfoldtdTfoldbuTonetdTonebuTprunetdTcrushtdTcrushbuTcollectT collectPruneTalltdRallbuRallduRanytdRanybuRanyduRonetdRonebuRprunetdR innermostR rootAbsPath extendAbsPathabsPathTrootPathpathsToT onePathToToneNonEmptyPathToT prunePathsToT uniquePathToTuniquePrunePathToTpathL exhaustPathL repeatPathLrootLpathRpathT testPathTKureMrunKureM fromKureM allTgeneric oneTgeneric allRgeneric anyRgeneric oneRgeneric childLgeneric attemptAny2 attemptAny3 attemptAny4 attemptAnyN attemptAny1N withArgumentT attemptOne2 attemptOne3 attemptOne4 attemptOneN attemptOne1N missingChild childLaux childL0of1 childL0of2 childL1of2 childL0of3 childL1of3 childL2of3 childL0of4 childL1of4 childL2of4 childL3of4 childLMofNbaseControl.CategoryCategoryGHC.BaseMonadfail Data.Monoidmempty Control.Monadguardmzero Control.ArrowArrow$fCategoryCatchLens$fMonoidTranslate$fArrowApplyTranslateKleisli$fArrowPlusTranslate$fArrowZeroTranslate$fArrowTranslate$fCategoryCatchTranslate$fCategoryTranslate$fMonadPlusTranslate$fMonadCatchTranslate$fMonadTranslate$fAlternativeTranslate$fApplicativeTranslate$fFunctorTranslate$fCategoryLens$fCategoryBiTranslate $fInjectionaa$fInjectionaMaybeMonoid$fPathContextAbsolutePath childrenT childrenR rmPathPrefix abs2pathTrequireUniquePath$fShowAbsolutePath Data.EitherEitherStringGHC.Errerror$fMonadCatchKureMSrunSSuccessFailure attemptAny2' attemptAny3' attemptAny4' attemptAnyN' attemptAny1N' attemptOne1' attemptOne2' attemptOne3' attemptOne4' liftArgument2 liftArgument3 liftArgument4 liftArgumentNliftArgument1N$fMonadS$fApplicativeS $fFunctorS$fApplicativeKureM$fFunctorKureM $fMonadKureM