--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
--- Portability : non-portable
+-- Portability : non-portable (local universal quantification)
--
-- \"Scrap your boilerplate\" --- Generic programming in Haskell
-- See <http://www.cs.vu.nl/boilerplate/>. The present module provides
--
-----------------------------------------------------------------------------
-module Data.Generics.Aliases (
+module Data.Generics.Aliases (
- -- * Combinators to \"make\" generic functions via cast
- mkT, mkQ, mkM, mkMp, mkR,
- extT, extQ, extM, extMp, extB, extR,
+ -- * Combinators to \"make\" generic functions via cast
+ mkT, mkQ, mkM, mkMp, mkR,
+ ext0, extT, extQ, extM, extMp, extB, extR,
- -- * Type synonyms for generic function types
- GenericT,
- GenericQ,
- GenericM,
- GenericB,
- GenericR,
+ -- * Type synonyms for generic function types
+ GenericT,
+ GenericQ,
+ GenericM,
+ GenericB,
+ GenericR,
Generic,
Generic'(..),
GenericT'(..),
GenericQ'(..),
GenericM'(..),
- -- * Inredients of generic functions
- orElse,
+ -- * Inredients of generic functions
+ orElse,
- -- * Function combinators on generic functions
- recoverMp,
- recoverQ,
- choiceMp,
- choiceQ,
+ -- * Function combinators on generic functions
+ recoverMp,
+ recoverQ,
+ choiceMp,
+ choiceQ,
- -- * Operators for (over-appreciated) unfolding
- gunfoldB,
- gunfoldR,
-
- -- * Type extension for unary type constructors
- ext1T,
- ext1M,
- ext1Q,
- ext1R
+ -- * Type extension for unary type constructors
+ ext1T,
+ ext1M,
+ ext1Q,
+ ext1R
) where
------------------------------------------------------------------------------
--
--- Combinators to "make" generic functions
--- We use type-safe cast in a number of ways to make generic functions.
+-- Combinators to "make" generic functions
+-- We use type-safe cast in a number of ways to make generic functions.
--
------------------------------------------------------------------------------
, Typeable b
)
=> (b -> b)
- -> a
-> a
-mkT f = case cast f of
- Just g -> g
- Nothing -> id
+ -> a
+mkT = extT id
-- | Make a generic query;
)
=> r
-> (b -> r)
- -> a
+ -> a
-> r
(r `mkQ` br) a = case cast a of
Just b -> br b
, Typeable b
)
=> (b -> m b)
- -> a
+ -> a
-> m a
mkM = extM return
-- | Flexible type extension
ext0 :: (Typeable a, Typeable b) => c a -> c b -> c a
-ext0 def ext = maybe def id (cast0 ext)
+ext0 def ext = maybe def id (gcast ext)
-- | Extend a generic transformation by a type-specific case
extT :: ( Typeable a
- , Typeable b
+ , Typeable b
)
=> (a -> a)
-> (b -> b)
-> a
-> a
-extT f = maybe f id . cast
+extT def ext = unT ((T def) `ext0` (T ext))
-- | Extend a generic query by a type-specific case
------------------------------------------------------------------------------
--
--- Type synonyms for generic function types
+-- Type synonyms for generic function types
--
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--
--- Generic unfolding
+-- Type extension for unary type constructors
--
------------------------------------------------------------------------------
--- | Construct an initial term with undefined immediate subterms
--- and then map over the skeleton to fill in proper terms.
-gunfoldB :: Data a
- => Constr
- -> (forall a. Data a => a)
- -> a
-gunfoldB c f = gmapT (const f) (fromConstr c)
-
-
--- | Monadic variation on \"gunfoldB\"
-gunfoldR :: (Monad m, Data a)
- => Constr
- -> (forall a. Data a => m a)
- -> m a
-gunfoldR c f = gmapM (const f) $ fromConstr c
-
-------------------------------------------------------------------------------
---
--- Type extension for unary type constructors
---
-------------------------------------------------------------------------------
+-- | Flexible type extension
+ext1 :: (Data a, Typeable1 t)
+ => c a
+ -> (forall a. Data a => c (t a))
+ -> c a
+ext1 def ext = maybe def id (dataCast1 ext)
-- | Type extension of transformations for unary type constructors
------------------------------------------------------------------------------
--
--- Type constructors for type-level lambdas
+-- Type constructors for type-level lambdas
--
------------------------------------------------------------------------------