1-----------------------------------------------------------------------------
3-- Module : Data.Generics.Extras
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
12-- Additional SYB combinators
14-----------------------------------------------------------------------------
16{-# LANGUAGE Rank2Types #-}
18module Data.Generics.Extras where
23-- Apply a top-down transformation, mutating a state when descending from parents to children
25-- For example, if we want to relabel bound variables with a different data constructor, we can do so:
27-- > data Expr = Var String
30-- > | LocalVar String deriving (Show, Data, Typeable)
32-- > test = App (Lam "a" (App (Var "a") (Var "b"))) (Var "a")
34-- > varsToLocals :: Expr -> Expr
35-- > varsToLocals = everywhereWithContext' [] (mkS go)
37-- > go locals (Var v) | v `elem` locals = (locals, LocalVar v)
38-- > go locals lam@(Lam local _) = (local : locals, lam)
39-- > go locals other = (locals, other)
41everywhereWithContextM' :: (Monad m, Data d) => s -> (forall d1. (Data d1) => s -> d1 -> m (s, d1)) -> d -> m d
42everywhereWithContextM' s0 f x = do
44 gmapM (everywhereWithContextM' s f) y
47-- Make a stateful transformation function
49mkS :: (Monad m, Data a, Data b) => (s -> a -> m (s, a)) -> s -> b -> m (s, b)
50mkS = extS (curry return)
53-- Extend a stateful transformation function
55extS :: (Monad m, Data a, Data b) => (s -> a -> m (s, a)) -> (s -> b -> m (s, b)) -> (s -> a -> m (s, a))
62 Just a'' -> return (s'', a'')
63 Nothing -> return (s', a')
64 Nothing -> return (s', a')
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list