{-# LANGUAGE RankNTypes, CPP #-}
module Data.Generics.Aliases (
mkT,
extT,
mkQ,
extQ,
mkM,
extM,
mkMp,
extMp,
mkR,
extR,
extB,
ext0,
GenericT,
GenericT'(..),
GenericQ,
GenericQ'(..),
GenericM,
GenericM'(..),
GenericR,
GenericB,
Generic,
Generic'(..),
orElse,
recoverMp,
recoverQ,
choiceMp,
choiceQ,
ext1,
ext1T,
ext1M,
ext1Q,
ext1R,
ext1B,
ext2,
ext2T,
ext2M,
ext2Q,
ext2R,
ext2B
) where
#ifdef __HADDOCK__
import Prelude
#endif
import Control.Monad
import Data.Data
mkT :: ( Typeable a
, Typeable b
)
=> (b -> b)
-> a
-> a
mkT :: forall a b. (Typeable a, Typeable b) => (b -> b) -> a -> a
mkT = forall a b.
(Typeable a, Typeable b) =>
(a -> a) -> (b -> b) -> a -> a
extT forall a. a -> a
id
mkQ :: ( Typeable a
, Typeable b
)
=> r
-> (b -> r)
-> a
-> r
(r
r mkQ :: forall a b r. (Typeable a, Typeable b) => r -> (b -> r) -> a -> r
`mkQ` b -> r
br) a
a = case forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast a
a of
Just b
b -> b -> r
br b
b
Maybe b
Nothing -> r
r
mkM :: ( Monad m
, Typeable a
, Typeable b
)
=> (b -> m b)
-> a
-> m a
mkM :: forall (m :: * -> *) a b.
(Monad m, Typeable a, Typeable b) =>
(b -> m b) -> a -> m a
mkM = forall (m :: * -> *) a b.
(Monad m, Typeable a, Typeable b) =>
(a -> m a) -> (b -> m b) -> a -> m a
extM forall (m :: * -> *) a. Monad m => a -> m a
return
mkMp :: ( MonadPlus m
, Typeable a
, Typeable b
)
=> (b -> m b)
-> a
-> m a
mkMp :: forall (m :: * -> *) a b.
(MonadPlus m, Typeable a, Typeable b) =>
(b -> m b) -> a -> m a
mkMp = forall (m :: * -> *) a b.
(Monad m, Typeable a, Typeable b) =>
(a -> m a) -> (b -> m b) -> a -> m a
extM (forall a b. a -> b -> a
const forall (m :: * -> *) a. MonadPlus m => m a
mzero)
mkR :: ( MonadPlus m
, Typeable a
, Typeable b
)
=> m b
-> m a
mkR :: forall (m :: * -> *) a b.
(MonadPlus m, Typeable a, Typeable b) =>
m b -> m a
mkR m b
f = forall (m :: * -> *) a. MonadPlus m => m a
mzero forall (m :: * -> *) a b.
(Monad m, Typeable a, Typeable b) =>
m a -> m b -> m a
`extR` m b
f
ext0 :: (Typeable a, Typeable b) => c a -> c b -> c a
ext0 :: forall a b (c :: * -> *).
(Typeable a, Typeable b) =>
c a -> c b -> c a
ext0 c a
def c b
ext = forall b a. b -> (a -> b) -> Maybe a -> b
maybe c a
def forall a. a -> a
id (forall {k} (a :: k) (b :: k) (c :: k -> *).
(Typeable a, Typeable b) =>
c a -> Maybe (c b)
gcast c b
ext)
extT :: ( Typeable a
, Typeable b
)
=> (a -> a)
-> (b -> b)
-> a
-> a
extT :: forall a b.
(Typeable a, Typeable b) =>
(a -> a) -> (b -> b) -> a -> a
extT a -> a
def b -> b
ext = forall x. T x -> x -> x
unT ((forall x. (x -> x) -> T x
T a -> a
def) forall a b (c :: * -> *).
(Typeable a, Typeable b) =>
c a -> c b -> c a
`ext0` (forall x. (x -> x) -> T x
T b -> b
ext))
extQ :: ( Typeable a
, Typeable b
)
=> (a -> r)
-> (b -> r)
-> a
-> r
extQ :: forall a b r.
(Typeable a, Typeable b) =>
(a -> r) -> (b -> r) -> a -> r
extQ a -> r
f b -> r
g a
a = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (a -> r
f a
a) b -> r
g (forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast a
a)
extM :: ( Monad m
, Typeable a
, Typeable b
)
=> (a -> m a)
-> (b -> m b)
-> a
-> m a
extM :: forall (m :: * -> *) a b.
(Monad m, Typeable a, Typeable b) =>
(a -> m a) -> (b -> m b) -> a -> m a
extM a -> m a
def b -> m b
ext = forall (m :: * -> *) x. M m x -> x -> m x
unM ((forall (m :: * -> *) x. (x -> m x) -> M m x
M a -> m a
def) forall a b (c :: * -> *).
(Typeable a, Typeable b) =>
c a -> c b -> c a
`ext0` (forall (m :: * -> *) x. (x -> m x) -> M m x
M b -> m b
ext))
extMp :: ( MonadPlus m
, Typeable a
, Typeable b
)
=> (a -> m a)
-> (b -> m b)
-> a
-> m a
extMp :: forall (m :: * -> *) a b.
(MonadPlus m, Typeable a, Typeable b) =>
(a -> m a) -> (b -> m b) -> a -> m a
extMp = forall (m :: * -> *) a b.
(Monad m, Typeable a, Typeable b) =>
(a -> m a) -> (b -> m b) -> a -> m a
extM
extB :: ( Typeable a
, Typeable b
)
=> a
-> b
-> a
extB :: forall a b. (Typeable a, Typeable b) => a -> b -> a
extB a
a = forall b a. b -> (a -> b) -> Maybe a -> b
maybe a
a forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast
extR :: ( Monad m
, Typeable a
, Typeable b
)
=> m a
-> m b
-> m a
extR :: forall (m :: * -> *) a b.
(Monad m, Typeable a, Typeable b) =>
m a -> m b -> m a
extR m a
def m b
ext = forall (m :: * -> *) x. R m x -> m x
unR ((forall (m :: * -> *) x. m x -> R m x
R m a
def) forall a b (c :: * -> *).
(Typeable a, Typeable b) =>
c a -> c b -> c a
`ext0` (forall (m :: * -> *) x. m x -> R m x
R m b
ext))
type GenericT = forall a. Data a => a -> a
newtype GenericT' = GT { GenericT' -> GenericT
unGT :: GenericT }
type GenericQ r = forall a. Data a => a -> r
newtype GenericQ' r = GQ { forall r. GenericQ' r -> GenericQ r
unGQ :: GenericQ r }
type GenericM m = forall a. Data a => a -> m a
newtype GenericM' m = GM { forall (m :: * -> *). GenericM' m -> GenericM m
unGM :: GenericM m }
type GenericB = forall a. Data a => a
type GenericR m = forall a. Data a => m a
type Generic c = forall a. Data a => a -> c a
data Generic' c = Generic' { forall (c :: * -> *). Generic' c -> Generic c
unGeneric' :: Generic c }
orElse :: Maybe a -> Maybe a -> Maybe a
Maybe a
x orElse :: forall a. Maybe a -> Maybe a -> Maybe a
`orElse` Maybe a
y = case Maybe a
x of
Just a
_ -> Maybe a
x
Maybe a
Nothing -> Maybe a
y
choiceMp :: MonadPlus m => GenericM m -> GenericM m -> GenericM m
choiceMp :: forall (m :: * -> *).
MonadPlus m =>
GenericM m -> GenericM m -> GenericM m
choiceMp GenericM m
f GenericM m
g a
x = GenericM m
f a
x forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` GenericM m
g a
x
choiceQ :: MonadPlus m => GenericQ (m r) -> GenericQ (m r) -> GenericQ (m r)
choiceQ :: forall (m :: * -> *) r.
MonadPlus m =>
GenericQ (m r) -> GenericQ (m r) -> GenericQ (m r)
choiceQ GenericQ (m r)
f GenericQ (m r)
g a
x = GenericQ (m r)
f a
x forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` GenericQ (m r)
g a
x
recoverMp :: MonadPlus m => GenericM m -> GenericM m
recoverMp :: forall (m :: * -> *). MonadPlus m => GenericM m -> GenericM m
recoverMp GenericM m
f = GenericM m
f forall (m :: * -> *).
MonadPlus m =>
GenericM m -> GenericM m -> GenericM m
`choiceMp` forall (m :: * -> *) a. Monad m => a -> m a
return
recoverQ :: MonadPlus m => r -> GenericQ (m r) -> GenericQ (m r)
recoverQ :: forall (m :: * -> *) r.
MonadPlus m =>
r -> GenericQ (m r) -> GenericQ (m r)
recoverQ r
r GenericQ (m r)
f = GenericQ (m r)
f forall (m :: * -> *) r.
MonadPlus m =>
GenericQ (m r) -> GenericQ (m r) -> GenericQ (m r)
`choiceQ` forall a b. a -> b -> a
const (forall (m :: * -> *) a. Monad m => a -> m a
return r
r)
#if __GLASGOW_HASKELL__ >= 707
#define Typeable1 Typeable
#define Typeable2 Typeable
#endif
ext1 :: (Data a, Typeable1 t)
=> c a
-> (forall d. Data d => c (t d))
-> c a
ext1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d. Data d => c (t d)) -> c a
ext1 c a
def forall d. Data d => c (t d)
ext = forall b a. b -> (a -> b) -> Maybe a -> b
maybe c a
def forall a. a -> a
id (forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c a)
dataCast1 forall d. Data d => c (t d)
ext)
ext1T :: (Data d, Typeable1 t)
=> (forall e. Data e => e -> e)
-> (forall f. Data f => t f -> t f)
-> d -> d
ext1T :: forall d (t :: * -> *).
(Data d, Typeable t) =>
GenericT -> (forall f. Data f => t f -> t f) -> d -> d
ext1T GenericT
def forall f. Data f => t f -> t f
ext = forall x. T x -> x -> x
unT ((forall x. (x -> x) -> T x
T GenericT
def) forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d. Data d => c (t d)) -> c a
`ext1` (forall x. (x -> x) -> T x
T forall f. Data f => t f -> t f
ext))
ext1M :: (Monad m, Data d, Typeable1 t)
=> (forall e. Data e => e -> m e)
-> (forall f. Data f => t f -> m (t f))
-> d -> m d
ext1M :: forall (m :: * -> *) d (t :: * -> *).
(Monad m, Data d, Typeable t) =>
(forall e. Data e => e -> m e)
-> (forall f. Data f => t f -> m (t f)) -> d -> m d
ext1M forall e. Data e => e -> m e
def forall f. Data f => t f -> m (t f)
ext = forall (m :: * -> *) x. M m x -> x -> m x
unM ((forall (m :: * -> *) x. (x -> m x) -> M m x
M forall e. Data e => e -> m e
def) forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d. Data d => c (t d)) -> c a
`ext1` (forall (m :: * -> *) x. (x -> m x) -> M m x
M forall f. Data f => t f -> m (t f)
ext))
ext1Q :: (Data d, Typeable1 t)
=> (d -> q)
-> (forall e. Data e => t e -> q)
-> d -> q
ext1Q :: forall d (t :: * -> *) q.
(Data d, Typeable t) =>
(d -> q) -> (forall e. Data e => t e -> q) -> d -> q
ext1Q d -> q
def forall e. Data e => t e -> q
ext = forall q x. Q q x -> x -> q
unQ ((forall q x. (x -> q) -> Q q x
Q d -> q
def) forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d. Data d => c (t d)) -> c a
`ext1` (forall q x. (x -> q) -> Q q x
Q forall e. Data e => t e -> q
ext))
ext1R :: (Monad m, Data d, Typeable1 t)
=> m d
-> (forall e. Data e => m (t e))
-> m d
ext1R :: forall (m :: * -> *) d (t :: * -> *).
(Monad m, Data d, Typeable t) =>
m d -> (forall e. Data e => m (t e)) -> m d
ext1R m d
def forall e. Data e => m (t e)
ext = forall (m :: * -> *) x. R m x -> m x
unR ((forall (m :: * -> *) x. m x -> R m x
R m d
def) forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d. Data d => c (t d)) -> c a
`ext1` (forall (m :: * -> *) x. m x -> R m x
R forall e. Data e => m (t e)
ext))
ext1B :: (Data a, Typeable1 t)
=> a
-> (forall b. Data b => (t b))
-> a
ext1B :: forall a (t :: * -> *).
(Data a, Typeable t) =>
a -> (forall b. Data b => t b) -> a
ext1B a
def forall b. Data b => t b
ext = forall x. B x -> x
unB ((forall x. x -> B x
B a
def) forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d. Data d => c (t d)) -> c a
`ext1` (forall x. x -> B x
B forall b. Data b => t b
ext))
ext2 :: (Data a, Typeable2 t)
=> c a
-> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2))
-> c a
ext2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2)) -> c a
ext2 c a
def forall d1 d2. (Data d1, Data d2) => c (t d1 d2)
ext = forall b a. b -> (a -> b) -> Maybe a -> b
maybe c a
def forall a. a -> a
id (forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a)
dataCast2 forall d1 d2. (Data d1, Data d2) => c (t d1 d2)
ext)
ext2T :: (Data d, Typeable2 t)
=> (forall e. Data e => e -> e)
-> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> t d1 d2)
-> d -> d
ext2T :: forall d (t :: * -> * -> *).
(Data d, Typeable t) =>
GenericT
-> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> t d1 d2)
-> d
-> d
ext2T GenericT
def forall d1 d2. (Data d1, Data d2) => t d1 d2 -> t d1 d2
ext = forall x. T x -> x -> x
unT ((forall x. (x -> x) -> T x
T GenericT
def) forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2)) -> c a
`ext2` (forall x. (x -> x) -> T x
T forall d1 d2. (Data d1, Data d2) => t d1 d2 -> t d1 d2
ext))
ext2M :: (Monad m, Data d, Typeable2 t)
=> (forall e. Data e => e -> m e)
-> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> m (t d1 d2))
-> d -> m d
ext2M :: forall (m :: * -> *) d (t :: * -> * -> *).
(Monad m, Data d, Typeable t) =>
(forall e. Data e => e -> m e)
-> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> m (t d1 d2))
-> d
-> m d
ext2M forall e. Data e => e -> m e
def forall d1 d2. (Data d1, Data d2) => t d1 d2 -> m (t d1 d2)
ext = forall (m :: * -> *) x. M m x -> x -> m x
unM ((forall (m :: * -> *) x. (x -> m x) -> M m x
M forall e. Data e => e -> m e
def) forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2)) -> c a
`ext2` (forall (m :: * -> *) x. (x -> m x) -> M m x
M forall d1 d2. (Data d1, Data d2) => t d1 d2 -> m (t d1 d2)
ext))
ext2Q :: (Data d, Typeable2 t)
=> (d -> q)
-> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> q)
-> d -> q
ext2Q :: forall d (t :: * -> * -> *) q.
(Data d, Typeable t) =>
(d -> q)
-> (forall d1 d2. (Data d1, Data d2) => t d1 d2 -> q) -> d -> q
ext2Q d -> q
def forall d1 d2. (Data d1, Data d2) => t d1 d2 -> q
ext = forall q x. Q q x -> x -> q
unQ ((forall q x. (x -> q) -> Q q x
Q d -> q
def) forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2)) -> c a
`ext2` (forall q x. (x -> q) -> Q q x
Q forall d1 d2. (Data d1, Data d2) => t d1 d2 -> q
ext))
ext2R :: (Monad m, Data d, Typeable2 t)
=> m d
-> (forall d1 d2. (Data d1, Data d2) => m (t d1 d2))
-> m d
ext2R :: forall (m :: * -> *) d (t :: * -> * -> *).
(Monad m, Data d, Typeable t) =>
m d -> (forall d1 d2. (Data d1, Data d2) => m (t d1 d2)) -> m d
ext2R m d
def forall d1 d2. (Data d1, Data d2) => m (t d1 d2)
ext = forall (m :: * -> *) x. R m x -> m x
unR ((forall (m :: * -> *) x. m x -> R m x
R m d
def) forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2)) -> c a
`ext2` (forall (m :: * -> *) x. m x -> R m x
R forall d1 d2. (Data d1, Data d2) => m (t d1 d2)
ext))
ext2B :: (Data a, Typeable2 t)
=> a
-> (forall d1 d2. (Data d1, Data d2) => (t d1 d2))
-> a
ext2B :: forall a (t :: * -> * -> *).
(Data a, Typeable t) =>
a -> (forall d1 d2. (Data d1, Data d2) => t d1 d2) -> a
ext2B a
def forall d1 d2. (Data d1, Data d2) => t d1 d2
ext = forall x. B x -> x
unB ((forall x. x -> B x
B a
def) forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
c a -> (forall d1 d2. (Data d1, Data d2) => c (t d1 d2)) -> c a
`ext2` (forall x. x -> B x
B forall d1 d2. (Data d1, Data d2) => t d1 d2
ext))
newtype T x = T { forall x. T x -> x -> x
unT :: x -> x }
newtype M m x = M { forall (m :: * -> *) x. M m x -> x -> m x
unM :: x -> m x }
newtype Q q x = Q { forall q x. Q q x -> x -> q
unQ :: x -> q }
newtype R m x = R { forall (m :: * -> *) x. R m x -> m x
unR :: m x }
newtype B x = B {forall x. B x -> x
unB :: x}