Safe Haskell | Safe-Inferred |
---|

Additional SYB combinators

- everywhereM' :: (Monad m, Data d) => (forall d1. Data d1 => d1 -> m d1) -> d -> m d
- everywhereWithContextM' :: (Monad m, Data d) => s -> (forall d1. Data d1 => s -> d1 -> m (s, d1)) -> d -> m d
- mkS :: (Monad m, Data a, Data b) => (s -> a -> m (s, a)) -> s -> b -> m (s, b)
- extS :: (Monad m, Data a, Data b) => (s -> a -> m (s, a)) -> (s -> b -> m (s, b)) -> s -> a -> m (s, a)

# Documentation

everywhereM' :: (Monad m, Data d) => (forall d1. Data d1 => d1 -> m d1) -> d -> m dSource

Apply a top-down monadic transformation everywhere

everywhereWithContextM' :: (Monad m, Data d) => s -> (forall d1. Data d1 => s -> d1 -> m (s, d1)) -> d -> m dSource

Apply a top-down transformation, mutating a state when descending from parents to children

For example, if we want to relabel bound variables with a different data constructor, we can do so:

data Expr = Var String | Lam String Test | App Test Test | LocalVar String deriving (Show, Data, Typeable) test = App (Lam "a" (App (Var "a") (Var "b"))) (Var "a") varsToLocals :: Expr -> Expr varsToLocals = everywhereWithContext' [] (mkS go) where go locals (Var v) | v `elem` locals = (locals, LocalVar v) go locals lam@(Lam local _) = (local : locals, lam) go locals other = (locals, other)