{-# OPTIONS_GHC -fno-warn-deprecations #-}
module Data.Generics.UniplateOn
(
module Data.Generics.Uniplate,
module Data.Generics.UniplateOn
) where
import Data.Generics.Uniplate
import Control.Monad(liftM)
type BiplateType from to = from -> ([to], [to] -> from)
universeOn :: Uniplate to => BiplateType from to -> from -> [to]
universeOn :: forall to from. Uniplate to => BiplateType from to -> from -> [to]
universeOn BiplateType from to
biplate from
x = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall on. Uniplate on => on -> [on]
universe forall a b. (a -> b) -> a -> b
$ forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ BiplateType from to
biplate from
x
childrenOn :: Uniplate to => BiplateType from to -> from -> [to]
childrenOn :: forall to from. Uniplate to => BiplateType from to -> from -> [to]
childrenOn BiplateType from to
biplate from
x = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ BiplateType from to
biplate from
x
transformOn :: Uniplate to => BiplateType from to -> (to -> to) -> from -> from
transformOn :: forall to from.
Uniplate to =>
BiplateType from to -> (to -> to) -> from -> from
transformOn BiplateType from to
biplate to -> to
f from
x = [to] -> from
generate forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall on. Uniplate on => (on -> on) -> on -> on
transform to -> to
f) [to]
current
where ([to]
current, [to] -> from
generate) = BiplateType from to
biplate from
x
transformOnM :: (Monad m, Uniplate to) => BiplateType from to -> (to -> m to) -> from -> m from
transformOnM :: forall (m :: * -> *) to from.
(Monad m, Uniplate to) =>
BiplateType from to -> (to -> m to) -> from -> m from
transformOnM BiplateType from to
biplate to -> m to
f from
x = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [to] -> from
generate forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) on.
(Monad m, Uniplate on) =>
(on -> m on) -> on -> m on
transformM to -> m to
f) [to]
current
where ([to]
current, [to] -> from
generate) = BiplateType from to
biplate from
x
rewriteOn :: Uniplate to => BiplateType from to -> (to -> Maybe to) -> from -> from
rewriteOn :: forall to from.
Uniplate to =>
BiplateType from to -> (to -> Maybe to) -> from -> from
rewriteOn BiplateType from to
biplate to -> Maybe to
f from
x = [to] -> from
generate forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall on. Uniplate on => (on -> Maybe on) -> on -> on
rewrite to -> Maybe to
f) [to]
current
where ([to]
current, [to] -> from
generate) = BiplateType from to
biplate from
x
rewriteOnM :: (Monad m, Uniplate to) => BiplateType from to -> (to -> m (Maybe to)) -> from -> m from
rewriteOnM :: forall (m :: * -> *) to from.
(Monad m, Uniplate to) =>
BiplateType from to -> (to -> m (Maybe to)) -> from -> m from
rewriteOnM BiplateType from to
biplate to -> m (Maybe to)
f from
x = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [to] -> from
generate forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) on.
(Monad m, Uniplate on) =>
(on -> m (Maybe on)) -> on -> m on
rewriteM to -> m (Maybe to)
f) [to]
current
where ([to]
current, [to] -> from
generate) = BiplateType from to
biplate from
x
descendOn :: Uniplate to => BiplateType from to -> (to -> to) -> from -> from
descendOn :: forall to from.
Uniplate to =>
BiplateType from to -> (to -> to) -> from -> from
descendOn BiplateType from to
biplate to -> to
f from
x = [to] -> from
generate forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map to -> to
f [to]
current
where ([to]
current, [to] -> from
generate) = BiplateType from to
biplate from
x
descendOnM :: (Monad m, Uniplate to) => BiplateType from to -> (to -> m to) -> from -> m from
descendOnM :: forall (m :: * -> *) to from.
(Monad m, Uniplate to) =>
BiplateType from to -> (to -> m to) -> from -> m from
descendOnM BiplateType from to
biplate to -> m to
f from
x = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [to] -> from
generate forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM to -> m to
f [to]
current
where ([to]
current, [to] -> from
generate) = BiplateType from to
biplate from
x
holesOn :: Uniplate to => BiplateType from to -> from -> [(to, to -> from)]
holesOn :: forall to from.
Uniplate to =>
BiplateType from to -> from -> [(to, to -> from)]
holesOn BiplateType from to
biplate from
x = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall {a} {c}. [a] -> ([a] -> c) -> [(a, a -> c)]
f (BiplateType from to
biplate from
x)
where f :: [a] -> ([a] -> c) -> [(a, a -> c)]
f [] [a] -> c
_ = []
f (a
x:[a]
xs) [a] -> c
gen = (a
x, [a] -> c
gen forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> [a]
:[a]
xs)) forall a. a -> [a] -> [a]
:
[a] -> ([a] -> c) -> [(a, a -> c)]
f [a]
xs ([a] -> c
gen forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
xforall a. a -> [a] -> [a]
:))
contextsOn :: Uniplate to => BiplateType from to -> from -> [(to, to -> from)]
contextsOn :: forall to from.
Uniplate to =>
BiplateType from to -> from -> [(to, to -> from)]
contextsOn BiplateType from to
biplate from
x = forall {b} {c}. Uniplate b => [(b, b -> c)] -> [(b, b -> c)]
f (forall to from.
Uniplate to =>
BiplateType from to -> from -> [(to, to -> from)]
holesOn BiplateType from to
biplate from
x)
where
f :: [(b, b -> c)] -> [(b, b -> c)]
f [(b, b -> c)]
xs = [ (b
y, b -> c
ctx forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> b
context)
| (b
child, b -> c
ctx) <- [(b, b -> c)]
xs
, (b
y, b -> b
context) <- forall on. Uniplate on => on -> [(on, on -> on)]
contexts b
child]
uniplateOnList :: BiplateType a b -> BiplateType [a] b
uniplateOnList :: forall a b. BiplateType a b -> BiplateType [a] b
uniplateOnList BiplateType a b
f [] = ([], \[] -> [])
uniplateOnList BiplateType a b
f (a
x:[a]
xs) =
([b]
a forall a. [a] -> [a] -> [a]
++ [b]
as,
\[b]
ns -> let ([b]
n1,[b]
n2) = forall a. Int -> [a] -> ([a], [a])
splitAt (forall (t :: * -> *) a. Foldable t => t a -> Int
length [b]
a) [b]
ns in [b] -> a
b [b]
n1 forall a. a -> [a] -> [a]
: [b] -> [a]
bs [b]
n2)
where
([b]
a , [b] -> a
b ) = BiplateType a b
f a
x
([b]
as, [b] -> [a]
bs) = forall a b. BiplateType a b -> BiplateType [a] b
uniplateOnList BiplateType a b
f [a]
xs