retrie-1.2.2: A powerful, easy-to-use codemodding tool for Haskell.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Retrie.Monad

Contents

- Retrie Computations
- Internal

Synopsis

- data Retrie a
- addImports :: AnnotatedImports -> Retrie ()
- apply :: [Rewrite Universe] -> Retrie ()
- applyWithStrategy :: Strategy (TransformT (WriterT Change IO)) -> [Rewrite Universe] -> Retrie ()
- applyWithUpdate :: ContextUpdater -> [Rewrite Universe] -> Retrie ()
- applyWithUpdateAndStrategy :: ContextUpdater -> Strategy (TransformT (WriterT Change IO)) -> [Rewrite Universe] -> Retrie ()
- focus :: Data k => [Query k v] -> Retrie ()
- ifChanged :: Retrie () -> Retrie () -> Retrie ()
- iterateR :: Int -> Retrie () -> Retrie ()
- query :: [Query Universe v] -> Retrie [(Context, Substitution, v)]
- queryWithUpdate :: ContextUpdater -> [Query Universe v] -> Retrie [(Context, Substitution, v)]
- topDownPrune :: Monad m => Strategy (TransformT (WriterT Change m))
- getGroundTerms :: Retrie a -> [GroundTerms]
- liftRWST :: RetrieComp a -> Retrie a
- runRetrie :: FixityEnv -> Retrie a -> CPP AnnotatedModule -> IO (a, CPP AnnotatedModule, Change)

# Retrie Computations

data Retrie a #

The `Retrie` monad is essentially `IO`, plus state containing the module that is being transformed. It is run once per target file.

It is special because it also allows Retrie to extract a set of `GroundTerms` from the `Retrie` computation without evaluating it.

Retrie uses the ground terms to select which files to target. This is the key optimization that allows Retrie to handle large codebases.

Note: Due to technical limitations, we cannot extract ground terms if you use `liftIO` before calling one of `apply`, `focus`, or `query` at least once. This will cause Retrie to attempt to parse every module in the target directory. In this case, please add a call to `focus` before the call to `liftIO`.

#### Instances

Instances details

MonadIO Retrie # |
Instance details Defined in Retrie.Monad Methods liftIO :: IO a -> Retrie a
Applicative Retrie # |
Instance details Defined in Retrie.Monad Methods pure :: a -> Retrie a # (<*>) :: Retrie (a -> b) -> Retrie a -> Retrie b liftA2 :: (a -> b -> c) -> Retrie a -> Retrie b -> Retrie c (*>) :: Retrie a -> Retrie b -> Retrie b (<*) :: Retrie a -> Retrie b -> Retrie a
Functor Retrie # |
Instance details Defined in Retrie.Monad Methods fmap :: (a -> b) -> Retrie a -> Retrie b # (<$) :: a -> Retrie b -> Retrie a #
Monad Retrie # |
Instance details Defined in Retrie.Monad Methods (>>=) :: Retrie a -> (a -> Retrie b) -> Retrie b (>>) :: Retrie a -> Retrie b -> Retrie b return :: a -> Retrie a #

addImports :: AnnotatedImports -> Retrie () #

Add imports to the module.

apply :: [Rewrite Universe] -> Retrie () #

Apply a set of rewrites. By default, rewrites are applied top-down, pruning the traversal at successfully changed AST nodes. See `topDownPrune`.

applyWithStrategy :: Strategy (TransformT (WriterT Change IO)) -> [Rewrite Universe] -> Retrie () #

Apply a set of rewrites with a custom traversal strategy.

applyWithUpdate :: ContextUpdater -> [Rewrite Universe] -> Retrie () #

Apply a set of rewrites with a custom context-update function.

applyWithUpdateAndStrategy :: ContextUpdater -> Strategy (TransformT (WriterT Change IO)) -> [Rewrite Universe] -> Retrie () #

Apply a set of rewrites with custom context-update and traversal strategy.

focus :: Data k => [Query k v] -> Retrie () #

Use the given queries/rewrites to select files for rewriting. Does not actually perform matching. This is useful if the queries/rewrites which best determine which files to target are not the first ones you run, and when you need to `liftIO` before running any queries/rewrites.

ifChanged :: Retrie () -> Retrie () -> Retrie () #

If the first `Retrie` computation makes a change to the module, run the second `Retrie` computation.

iterateR :: Int -> Retrie () -> Retrie () #

Iterate given `Retrie` computation until it no longer makes changes, or N times, whichever happens first.

query :: [Query Universe v] -> Retrie [(Context, Substitution, v)] #

Query the AST. Each match returns the context of the match, a substitution mapping quantifiers to matched subtrees, and the query's value.

queryWithUpdate :: ContextUpdater -> [Query Universe v] -> Retrie [(Context, Substitution, v)] #

Query the AST with a custom context update function.

topDownPrune :: Monad m => Strategy (TransformT (WriterT Change m)) #

Top-down traversal that does not descend into changed AST nodes. Default strategy used by `apply`.

# Internal

getGroundTerms :: Retrie a -> [GroundTerms] #

Helper to extract the ground terms from a `Retrie` computation.

liftRWST :: RetrieComp a -> Retrie a #

runRetrie :: FixityEnv -> Retrie a -> CPP AnnotatedModule -> IO (a, CPP AnnotatedModule, Change) #

Run the `Retrie` monad.