-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Combinators for Strategic Programming -- -- The Kansas University Rewrite Engine (KURE) is a domain-specific -- language for strategic rewriting. KURE was inspired by Stratego and -- StrategyLib, and has similarities with Scrap Your Boilerplate and -- Uniplate. -- -- The basic transformation functionality can be found in -- Language.KURE.Translate, and the traversal functionality can be -- found in Language.KURE.Walker. Several basic examples of using -- KURE are provided in the source-code bundle. For larger examples, see -- the HERMIT or HTML-KURE packages. -- -- You can read about KURE in the following article: -- -- KURE: A Haskell-Embedded Strategic Programming Language with Custom -- Closed Universes. Neil Sculthorpe and Nicolas Frisby and Andy Gill. -- 2013. http://www.ittc.ku.edu/~neil/papers_and_talks/kure.pdf @package kure @version 2.12.2 -- | This module provides some utility arrow routing combinators. module Language.KURE.Combinators.Arrow -- | Apply a pure function to the result of an arrow. result :: Arrow bi => (b -> c) -> bi a b -> bi a c -- | Apply a pure function to the argument to an arrow. argument :: Arrow bi => (a -> b) -> bi b c -> bi a c -- | Apply an arrow to the first element of a pair, discarding the second -- element. toFst :: Arrow bi => bi a b -> bi (a, x) b -- | Apply an arrow to the second element of a pair, discarding the first -- element. toSnd :: Arrow bi => bi a b -> bi (x, a) b -- | A pure arrow that swaps the elements of a pair. swap :: Arrow bi => bi (a, b) (b, a) -- | A pure arrow that duplicates its argument. fork :: Arrow bi => bi a (a, a) -- | Tag the result of an arrow with its argument. forkFirst :: Arrow bi => bi a b -> bi a (b, a) -- | Tag the result of an arrow with its argument. forkSecond :: Arrow bi => bi a b -> bi a (a, b) -- | An arrow with a constant result. constant :: Arrow bi => b -> bi a b -- | Sequence (from left to right) a collection of Categorys. serialise :: (Foldable f, Category bi) => f (bi a a) -> bi a a -- | Apply a collection of arrows to the same input, combining their -- results in a monoid. parallelise :: (Foldable f, Arrow bi, Monoid b) => f (bi a b) -> bi a b -- | This module provides conditional monadic combinators. module Language.KURE.Combinators.Monad -- | Similar to guard, but invokes fail rather than -- mzero. guardMsg :: Monad m => Bool -> String -> m () -- | As guardMsg, but with a default error message. guardM :: Monad m => Bool -> m () -- | As guardMsg, but with an m Bool as argument. guardMsgM :: Monad m => m Bool -> String -> m () -- | if-then-else lifted over a monadic predicate. ifM :: Monad m => m Bool -> m a -> m a -> m a -- | If the monadic predicate holds then perform the monadic action, else -- fail. whenM :: Monad m => m Bool -> m a -> m a -- | If the monadic predicate holds then fail, else perform the monadic -- action. unlessM :: Monad m => m Bool -> m a -> m a -- | This module provides classes for catch-like operations on -- Monads. module Language.KURE.MonadCatch -- | Monads with a catch for fail. The following law is -- expected to hold: -- --
-- fail msg `catchM` f == f msg --class Monad m => MonadCatch m catchM :: MonadCatch m => m a -> (String -> m a) -> m a -- | KureM is the minimal structure that can be an instance of -- MonadCatch. The KURE user is free to either use KureM or -- provide their own monad. KureM is essentially the same as -- Either String, except that it supports a -- MonadCatch instance which Either String does not -- (because its fail method calls error) A major advantage -- of this is that monadic pattern match failures are caught safely. data KureM a -- | Eliminator for KureM. runKureM :: (a -> b) -> (String -> b) -> KureM a -> b -- | Get the value from a KureM, providing a function to handle the -- error case. fromKureM :: (String -> a) -> KureM a -> a -- | Lift a KureM computation to any other monad. liftKureM :: Monad m => KureM a -> m a -- | Lift a computation from the IO monad, catching failures in the -- target monad. liftAndCatchIO :: (MonadCatch m, MonadIO m) => IO a -> m a -- | A monadic catch that ignores the error message. (<+) :: MonadCatch m => m a -> m a -> m a -- | Select the first monadic computation that succeeds, discarding any -- thereafter. catchesM :: (Foldable f, MonadCatch m) => f (m a) -> m a -- | Catch a failing monadic computation, making it succeed with a constant -- value. tryM :: MonadCatch m => a -> m a -> m a -- | Catch a failing monadic computation, making it succeed with -- mempty. mtryM :: (MonadCatch m, Monoid a) => m a -> m a -- | Catch a failing monadic computation, making it succeed with an error -- message. attemptM :: MonadCatch m => m a -> m (Either String a) -- | Determine if a monadic computation succeeds. testM :: MonadCatch m => m a -> m Bool -- | Fail if the monadic computation succeeds; succeed with () if -- it fails. notM :: MonadCatch m => m a -> m () -- | Modify the error message of a failing monadic computation. Successful -- computations are unaffected. modFailMsg :: MonadCatch m => (String -> String) -> m a -> m a -- | Set the error message of a failing monadic computation. Successful -- computations are unaffected. setFailMsg :: MonadCatch m => String -> m a -> m a -- | Add a prefix to the error message of a failing monadic computation. -- Successful computations are unaffected. prefixFailMsg :: MonadCatch m => String -> m a -> m a -- | Use the given error message whenever a monadic pattern match failure -- occurs. withPatFailMsg :: MonadCatch m => String -> m a -> m a instance Eq a => Eq (KureM a) instance Show a => Show (KureM a) instance MonadCatch IO instance Applicative KureM instance Functor KureM instance MonadCatch KureM instance Monad KureM -- | This module defines Translate and Rewrite, the main KURE -- types. Rewrite is just a special case of Translate, and -- so any function that operates on Translate is also applicable -- to Rewrite. -- -- Translate is an instance of the Monad and Arrow -- type-class families, and consequently many of the desirable -- combinators over Translate and Rewrite are special cases -- of existing monadic or arrow combinators. -- Language.KURE.Combinators provides some additional combinators -- that aren't in the standard libraries. module Language.KURE.Translate -- | An abstract representation of a transformation from a value of type -- a in a context c to a monadic value of type m -- b. The Translate type is the basis of the entire KURE -- library. data Translate c m a b -- | A Translate that shares the same source and target type. type Rewrite c m a = Translate c m a a -- | Apply a Translate to a value and its context. apply :: Translate c m a b -> c -> a -> m b -- | The primitive way of building a Translate. translate :: (c -> a -> m b) -> Translate c m a b -- | The primitive way of building a Rewrite. rewrite :: (c -> a -> m a) -> Rewrite c m a -- | Build a Translate that doesn't depend on the context. contextfreeT :: (a -> m b) -> Translate c m a b -- | Build a Translate that doesn't depend on the value. contextonlyT :: (c -> m b) -> Translate c m a b -- | Build a constant Translate from a monadic computation. constT :: m b -> Translate c m a b instance (Monad m, Monoid b) => Monoid (Translate c m a b) instance Monad m => ArrowApply (Translate c m) instance MonadPlus m => ArrowPlus (Translate c m) instance MonadPlus m => ArrowZero (Translate c m) instance Monad m => Arrow (Translate c m) instance Monad m => Category (Translate c m) instance MonadIO m => MonadIO (Translate c m a) instance MonadPlus m => MonadPlus (Translate c m a) instance MonadCatch m => MonadCatch (Translate c m a) instance Monad m => Monad (Translate c m a) instance Alternative m => Alternative (Translate c m a) instance Applicative m => Applicative (Translate c m a) instance Functor m => Functor (Translate c m a) -- | This module provides a type class for injective functions (and their -- projections), and some useful interactions with Translate. module Language.KURE.Injection -- | A class of injective functions from a to b, and -- their projections. The following law is expected to hold: -- --
-- project (inject a) == Just a --class Injection a b inject :: Injection a b => a -> b project :: Injection a b => b -> Maybe a -- | Injects a value and lifts it into a Monad. injectM :: (Monad m, Injection a g) => a -> m g -- | Projects a value and lifts it into a Monad, with the -- possibility of failure. projectM :: (Monad m, Injection a g) => g -> m a -- | As projectM, but takes a custom error message to use if -- projection fails. projectWithFailMsgM :: (Monad m, Injection a g) => String -> g -> m a -- | Lifted inject. injectT :: (Monad m, Injection a g) => Translate c m a g -- | Lifted project, the Translate fails if the projection -- fails. projectT :: (Monad m, Injection a g) => Translate c m g a -- | Convert a Translate over an injected value into a -- Translate over a non-injected value. extractT :: (Monad m, Injection a g) => Translate c m g b -> Translate c m a b -- | Promote a Translate over a value into a Translate over -- an injection of that value, (failing if that injected value cannot be -- projected). promoteT :: (Monad m, Injection a g) => Translate c m a b -> Translate c m g b -- | As promoteT, but takes a custom error message to use if -- promotion fails. promoteWithFailMsgT :: (Monad m, Injection a g) => String -> Translate c m a b -> Translate c m g b -- | Convert a Rewrite over an injected value into a Rewrite -- over a projection of that value, (failing if that injected value -- cannot be projected). extractR :: (Monad m, Injection a g) => Rewrite c m g -> Rewrite c m a -- | Promote a Rewrite into over a value into a Rewrite over -- an injection of that value, (failing if that injected value cannot be -- projected). promoteR :: (Monad m, Injection a g) => Rewrite c m a -> Rewrite c m g -- | As extractR, but takes a custom error message to use if -- extraction fails. extractWithFailMsgR :: (Monad m, Injection a g) => String -> Rewrite c m g -> Rewrite c m a -- | As promoteR, but takes a custom error message to use if -- promotion fails. promoteWithFailMsgR :: (Monad m, Injection a g) => String -> Rewrite c m a -> Rewrite c m g instance Injection a (Maybe a) instance Injection a a -- | A bi-directional translation is a translation that can be applied in -- either direction. module Language.KURE.BiTranslate -- | An undirected Translate. data BiTranslate c m a b -- | A BiTranslate that shares the same source and target type. type BiRewrite c m a = BiTranslate c m a a -- | Construct a BiTranslate from two opposite Translates. bidirectional :: Translate c m a b -> Translate c m b a -> BiTranslate c m a b -- | Extract the foreward Translate from a BiTranslate. forewardT :: BiTranslate c m a b -> Translate c m a b -- | Extract the backward Translate from a BiTranslate. backwardT :: BiTranslate c m a b -> Translate c m b a -- | Try the BiRewrite forewards, then backwards if that fails. -- Useful when you know which rule you want to apply, but not which -- direction to apply it in. whicheverR :: MonadCatch m => BiRewrite c m a -> Rewrite c m a -- | Invert the forewards and backwards directions of a BiTranslate. invertBiT :: BiTranslate c m a b -> BiTranslate c m b a -- | Perform the argument translation before either direction of the -- bidirectional rewrite. beforeBiR :: Monad m => Translate c m a b -> (b -> BiRewrite c m a) -> BiRewrite c m a instance Monad m => Category (BiTranslate c m) -- | This module provides a variety of combinators over Translate -- and Rewrite. module Language.KURE.Combinators.Translate -- | The identity Rewrite. idR :: Monad m => Rewrite c m a -- | An always successful Translate. successT :: Monad m => Translate c m a () -- | Extract the current context. contextT :: Monad m => Translate c m a c -- | Expose the current context and value. exposeT :: Monad m => Translate c m a (c, a) -- | Lift a Translate to operate on a derived context. liftContext :: (c -> c') -> Translate c' m a b -> Translate c m a b -- | Look at the argument to the Translate before choosing which -- Translate to use. readerT :: (a -> Translate c m a b) -> Translate c m a b -- | Convert the monadic result of a Translate into a result in -- another monad. resultT :: (m b -> n d) -> Translate c m a b -> Translate c n a d -- | Attempt each Translate until one succeeds, then return that -- result and discard the rest of the Translates. catchesT :: MonadCatch m => [Translate c m a b] -> Translate c m a b -- | Map a Translate over a list. mapT :: (Traversable t, Monad m) => Translate c m a b -> Translate c m (t a) (t b) -- | An identity translation that resembles a monadic join. joinT :: Translate c m (m a) a -- | Fail if the Boolean is False, succeed if the Boolean is True. guardT :: Monad m => Translate c m Bool () -- | Catch a failing Rewrite, making it into an identity. tryR :: MonadCatch m => Rewrite c m a -> Rewrite c m a -- | Perform a collection of rewrites in sequence, requiring all to -- succeed. andR :: (Foldable f, Monad m) => f (Rewrite c m a) -> Rewrite c m a -- | Perform a collection of rewrites in sequence, succeeding if any -- succeed. orR :: (Functor f, Foldable f, MonadCatch m) => f (Rewrite c m a) -> Rewrite c m a -- | Perform two rewrites in sequence, succeeding if one or both succeed. (>+>) :: MonadCatch m => Rewrite c m a -> Rewrite c m a -> Rewrite c m a -- | Repeat a Rewrite until it fails, then return the result before -- the failure. Requires at least the first attempt to succeed. repeatR :: MonadCatch m => Rewrite c m a -> Rewrite c m a -- | Look at the argument to a Rewrite, and choose to be either -- idR or a failure. acceptR :: Monad m => (a -> Bool) -> Rewrite c m a -- | As acceptR, but takes a custom failure message. acceptWithFailMsgR :: Monad m => (a -> Bool) -> String -> Rewrite c m a -- | A generalisation of acceptR where the predicate is a -- Translate. accepterR :: Monad m => Translate c m a Bool -> Rewrite c m a -- | Makes an Rewrite fail if the result value equals the argument -- value. changedR :: (MonadCatch m, Eq a) => Rewrite c m a -> Rewrite c m a -- | Makes a Rewrite fail if the result value and the argument value -- satisfy the equality predicate. This is a generalisation of -- changedR. changedR = changedByR (==) changedByR :: MonadCatch m => (a -> a -> Bool) -> Rewrite c m a -> Rewrite c m a -- | An identity Rewrite with side-effects. sideEffectR :: Monad m => (c -> a -> m ()) -> Rewrite c m a -- | The AnyR transformer, in combination with wrapAnyR and -- unwrapAnyR, causes a sequence of rewrites to succeed if at -- least one succeeds, converting failures to identity rewrites. data AnyR m a -- | Wrap a Rewrite using the AnyR monad transformer. wrapAnyR :: MonadCatch m => Rewrite c m a -> Rewrite c (AnyR m) a -- | Unwrap a Rewrite from the AnyR monad transformer. unwrapAnyR :: Monad m => Rewrite c (AnyR m) a -> Rewrite c m a -- | The OneR transformer, in combination with wrapOneR and -- unwrapOneR, causes a sequence of rewrites to only apply the -- first success, converting the remainder (and failures) to identity -- rewrites. data OneR m a -- | Wrap a Rewrite using the OneR monad transformer. wrapOneR :: MonadCatch m => Rewrite c m g -> Rewrite c (OneR m) g -- | Unwrap a Rewrite from the OneR monad transformer. unwrapOneR :: Monad m => Rewrite c (OneR m) a -> Rewrite c m a instance MonadCatch m => MonadCatch (OneR m) instance Monad m => Monad (OneR m) instance MonadCatch m => MonadCatch (AnyR m) instance Monad m => Monad (AnyR m) -- | This module provides various monadic and arrow combinators that are -- useful when working with Translates and Rewrites. module Language.KURE.Combinators -- | This module provides several Path abstractions, used for denoting a -- path through the tree. module Language.KURE.Path -- | A Path is just a list. The intent is that a path represents a -- route through the tree from an arbitrary node. type Path crumb = [crumb] -- | A SnocPath is a list stored in reverse order. newtype SnocPath crumb SnocPath :: [crumb] -> SnocPath crumb -- | A class of things that can be extended by crumbs. Typically, -- c is a context type. The typical use is to extend an -- AbsolutePath stored in the context (during tree traversal). -- Note however, that if an AbsolutePath is not stored in the -- context, an instance can still be declared with (@@ -- crumb) as an identity operation. class ExtendPath c crumb | c -> crumb (@@) :: ExtendPath c crumb => c -> crumb -> c -- | Convert a SnocPath to a Path. O(n). snocPathToPath :: SnocPath crumb -> Path crumb -- | Convert a Path to a SnocPath. O(n). pathToSnocPath :: Path crumb -> SnocPath crumb -- | Get the last crumb from a SnocPath. O(1). lastCrumb :: SnocPath crumb -> Maybe crumb -- | A SnocPath from a local origin. type LocalPath = SnocPath -- | A SnocPath from the root. type AbsolutePath = SnocPath -- | A class for contexts that store the current AbsolutePath, -- allowing transformations to depend upon it. class ReadPath c crumb | c -> crumb absPath :: ReadPath c crumb => c -> AbsolutePath crumb -- | Lifted version of lastCrumb. lastCrumbT :: (ReadPath c crumb, Monad m) => Translate c m a crumb -- | Lifted version of absPath. absPathT :: (ReadPath c crumb, Monad m) => Translate c m a (AbsolutePath crumb) instance Eq crumb => Eq (SnocPath crumb) instance ReadPath (AbsolutePath crumb) crumb instance ExtendPath (SnocPath crumb) crumb instance Show crumb => Show (SnocPath crumb) instance Monoid (SnocPath crumb) -- | This module provides a utility data type for extending an existing -- context with extra information. The idea is that, after defining class -- instances for any user-specific contextual operations, it can be used -- for any ad-hoc context extensions. See the treatment of -- ExtendPath as an example. module Language.KURE.ExtendableContext -- | A context transformer, for augmenting a context with additional -- information. data ExtendContext c e -- | Extend a context with some additional information. extendContext :: e -> c -> ExtendContext c e -- | Retrieve the base context (without the extra information). baseContext :: ExtendContext c e -> c -- | Retrieve the extra contextual information. extraContext :: ExtendContext c e -> e instance (ExtendPath c crumb, ExtendPath e crumb) => ExtendPath (ExtendContext c e) crumb -- | This module provides (unsafe) debugging/tracing combinators. module Language.KURE.Debug -- | trace output of the value being rewritten; use for debugging only. debugR :: (Monad m, Show a) => Int -> String -> Rewrite c m a -- | This module defines the KURE Lens type, along with some useful -- operations. module Language.KURE.Lens -- | A Lens is a way to focus on a sub-structure of type b -- from a structure of type a. data Lens c m a b -- | The primitive way of building a Lens. 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). lens :: Translate c m a ((c, b), b -> m a) -> Lens c m a b -- | Convert a Lens into a Translate that produces a -- sub-structure (and its context) and an unfocussing function. lensT :: Lens c m a b -> Translate c m a ((c, b), b -> m a) -- | Apply a Rewrite at a point specified by a Lens. focusR :: Monad m => Lens c m a b -> Rewrite c m b -> Rewrite c m a -- | Apply a Translate at a point specified by a Lens. focusT :: Monad m => Lens c m a b -> Translate c m b d -> Translate c m a d -- | Construct a Lens from two pure functions. pureL :: Monad m => (a -> b) -> (b -> a) -> Lens c m a b -- | The failing Lens. failL :: Monad m => String -> Lens c m a b -- | A Lens 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 (as by then it is too late to use an alternative -- Lens). This means that, in theory, a use of catchL could -- cause a succeeding Lens application to fail. But provided -- lens is used correctly, this should never happen. catchL :: MonadCatch m => Lens c m a b -> (String -> Lens c m a b) -> Lens c m a b -- | Check if the focusing succeeds, and additionally whether unfocussing -- from an unchanged value would succeed. testLensT :: MonadCatch m => Lens c m a b -> Translate c m a Bool -- | Construct a Lens from a BiTranslate. bidirectionalL :: Monad m => BiTranslate c m a b -> Lens c m a b -- | A Lens to the injection of a value. injectL :: (Monad m, Injection a g) => Lens c m a g -- | A Lens to the projection of a value. projectL :: (Monad m, Injection a g) => Lens c m g a instance Monad m => Category (Lens c m) -- | This module provides combinators that traverse a tree. -- -- Note that all traversals take place on the node, its children, or its -- descendents. Deliberately, there is no mechanism for "ascending" the -- tree. module Language.KURE.Walker -- | Walker captures the ability to walk over a tree containing -- nodes of type g, using a specific context c. -- -- Minimal complete definition: allR. -- -- Default definitions are provided for anyR, oneR, -- allT, oneT, and childL, but they may be -- overridden for efficiency. class Walker c g where allT = unwrapAllT . allR . wrapAllT oneT = unwrapOneT . allR . wrapOneT anyR = unwrapAnyR . allR . wrapAnyR oneR = unwrapOneR . allR . wrapOneR childL = childL_default allR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g allT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g b oneT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g b anyR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g oneR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g childL :: (Walker c g, ReadPath c crumb, Eq crumb, MonadCatch m) => crumb -> Lens c m g g -- | Apply a Rewrite to a specified child. childR :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => crumb -> Rewrite c m g -> Rewrite c m g -- | Apply a Translate to a specified child. childT :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => crumb -> Translate c m g b -> Translate c m g b -- | Apply a Rewrite in a top-down manner, succeeding if they all -- succeed. alltdR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite in a bottom-up manner, succeeding if they all -- succeed. allbuR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite twice, in a top-down and bottom-up way, using -- one single tree traversal, succeeding if they all succeed. allduR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite in a top-down manner, succeeding if any -- succeed. anytdR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite in a bottom-up manner, succeeding if any -- succeed. anybuR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite twice, in a top-down and bottom-up way, using -- one single tree traversal, succeeding if any succeed. anyduR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite to the first node for which it can succeed, in -- a top-down traversal. onetdR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite to the first node for which it can succeed, in -- a bottom-up traversal. onebuR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Attempt to apply a Rewrite in a top-down manner, pruning at -- successful rewrites. prunetdR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | A fixed-point traveral, starting with the innermost term. innermostR :: (Walker c g, MonadCatch m) => Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite to the largest node(s) that satisfy the -- predicate, requiring all to succeed. allLargestR :: (Walker c g, MonadCatch m) => Translate c m g Bool -> Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite to the largest node(s) that satisfy the -- predicate, succeeding if any succeed. anyLargestR :: (Walker c g, MonadCatch m) => Translate c m g Bool -> Rewrite c m g -> Rewrite c m g -- | Apply a Rewrite to the first node for which it can succeed -- among the largest node(s) that satisfy the predicate. oneLargestR :: (Walker c g, MonadCatch m) => Translate c m g Bool -> Rewrite c m g -> Rewrite c m g -- | Fold a tree in a top-down manner, using a single Translate for -- each node. foldtdT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g b -- | Fold a tree in a bottom-up manner, using a single Translate for -- each node. foldbuT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g b -- | Apply a Translate to the first node for which it can succeed, -- in a top-down traversal. onetdT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g b -- | Apply a Translate to the first node for which it can succeed, -- in a bottom-up traversal. onebuT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g b -- | Attempt to apply a Translate in a top-down manner, pruning at -- successes. prunetdT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g b -- | An always successful top-down fold, replacing failures with -- mempty. crushtdT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g b -- | An always successful bottom-up fold, replacing failures with -- mempty. crushbuT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g b -> Translate c m g b -- | An always successful traversal that collects the results of all -- successful applications of a Translate in a list. collectT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g [b] -- | Like collectT, but does not traverse below successes. collectPruneT :: (Walker c g, MonadCatch m) => Translate c m g b -> Translate c m g [b] -- | Apply a Translate to the largest node(s) that satisfy the -- predicate, combining the results in a monoid. allLargestT :: (Walker c g, MonadCatch m, Monoid b) => Translate c m g Bool -> Translate c m g b -> Translate c m g b -- | Apply a Translate to the first node for which it can succeed -- among the largest node(s) that satisfy the predicate. oneLargestT :: (Walker c g, MonadCatch m) => Translate c m g Bool -> Translate c m g b -> Translate c m g b -- | List the children of the current node. childrenT :: (ReadPath c crumb, Walker c g, MonadCatch m) => Translate c m g [crumb] -- | Test if the type of the current node summand matches the type of the -- argument. Note that the argument value is never inspected, it -- is merely a proxy for a type argument. summandIsTypeT :: (MonadCatch m, Injection a g) => a -> Translate c m g Bool -- | Construct a Lens by following a Path. pathL :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Lens c m g g -- | Build a Lens from the root to a point specified by a -- LocalPath. localPathL :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => LocalPath crumb -> Lens c m g g -- | Construct a Lens that points to the last node at which the -- Path can be followed. exhaustPathL :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Lens c m g g -- | Repeat as many iterations of the Path as possible. repeatPathL :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Lens c m g g -- | Apply a Rewrite at a point specified by a Path. pathR :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Rewrite c m g -> Rewrite c m g -- | Apply a Translate at a point specified by a Path. pathT :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Translate c m g b -> Translate c m g b -- | Apply a Rewrite at a point specified by a LocalPath. localPathR :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => LocalPath crumb -> Rewrite c m g -> Rewrite c m g -- | Apply a Translate at a point specified by a LocalPath. localPathT :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => LocalPath crumb -> Translate c m g b -> Translate c m g b -- | Check if it is possible to construct a Lens along this path -- from the current node. testPathT :: (ReadPath c crumb, Eq crumb, Walker c g, MonadCatch m) => Path crumb -> Translate c m g Bool instance MonadCatch (GetChild c g) instance Monad (GetChild c g) instance MonadCatch m => MonadCatch (OneT w m) instance Monad m => Monad (OneT w m) instance (Monoid w, MonadCatch m) => MonadCatch (AllT w m) instance (Monoid w, Monad m) => Monad (AllT w m) -- | This module provides combinators to find LocalPaths sub-nodes -- specified by a predicate. module Language.KURE.Pathfinder -- | A context transformer that adds a LocalPath (from the current -- node) to the context. type WithLocalPath c crumb = ExtendContext c (LocalPath crumb) -- | Apply a translation that stores a LocalPath in the context -- (starting at the current node). withLocalPathT :: Translate (WithLocalPath c crumb) m a b -> Translate c m a b -- | Extract the current LocalPath from the context. exposeLocalPathT :: Monad m => Translate (WithLocalPath c crumb) m a (LocalPath crumb) -- | Return the current LocalPath if the predicate translation -- succeeds. acceptLocalPathT :: Monad m => Translate c m g Bool -> Translate (WithLocalPath c crumb) m g (LocalPath crumb) -- | Find the LocalPaths to every node that satisfies the predicate. pathsToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g [LocalPath crumb] -- | Find the LocalPath to the first node that satisfies the -- predicate (in a pre-order traversal). onePathToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g (LocalPath crumb) -- | Find the LocalPath to the first descendent node that satisfies -- the predicate (in a pre-order traversal). oneNonEmptyPathToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g (LocalPath crumb) -- | Find the LocalPaths to every node that satisfies the predicate, -- ignoring nodes below successes. prunePathsToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g [LocalPath crumb] -- | Find the LocalPath to the node that satisfies the predicate, -- failing if that does not uniquely identify a node. uniquePathToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g (LocalPath crumb) -- | Build a LocalPath to the node that satisfies the predicate, -- failing if that does not uniquely identify a node (ignoring nodes -- below successes). uniquePrunePathToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g (LocalPath crumb) -- | This is the main import module for KURE, which exports all the major -- components. The basic transformation functionality can be found in -- Language.KURE.Translate, and the traversal functionality can be -- found in Language.KURE.Walker. module Language.KURE