-- Stability : experimental
-- Portability : non-portable
--
--- "Scrap your boilerplate" --- Generic programming in Haskell
--- See <http://www.cs.vu.nl/boilerplate/>.
+-- \"Scrap your boilerplate\" --- Generic programming in Haskell
+-- See <http://www.cs.vu.nl/boilerplate/>. The present module provides
+-- a number of declarations for typical generic function types,
+-- corresponding type case, and others.
--
-----------------------------------------------------------------------------
module Data.Generics.Aliases (
-- * Combinators to \"make\" generic functions via cast
- mkT, mkQ, mkM, mkF, mkB,
- extT, extQ, extM, extF, extB,
+ mkT, mkQ, mkM, mkMp, mkB,
+ extT, extQ, extM, extMp, extB,
-- * Type synonyms for generic function types
GenericT,
orElse,
-- * Function combinators on generic functions
- recoverF,
+ recoverMp,
recoverQ,
- choiceF,
+ choiceMp,
choiceQ
) where
-- resort to return otherwise
--
mkM :: ( Monad m,
- Typeable a,
- Typeable b,
- Typeable (m a),
- Typeable (m b)
+ Typeable a,
+ Typeable b
)
=> (b -> m b) -> a -> m a
-mkM f = case cast f of
+mkM f = case castarr f of
Just g -> g
Nothing -> return
-- | Make a generic monadic transformation for MonadPlus;
-- use \"const mzero\" (i.e., failure) instead of return as default.
--
-mkF :: ( MonadPlus m,
- Typeable a,
- Typeable b,
- Typeable (m a),
- Typeable (m b)
- )
- => (b -> m b) -> a -> m a
-mkF = maybe (const mzero) id . cast
+mkMp :: ( MonadPlus m,
+ Typeable a,
+ Typeable b
+ )
+ => (b -> m b) -> a -> m a
+mkMp = maybe (const mzero) id . castarr
-- | Make a generic builder;
--
mkB :: ( MonadPlus m,
Typeable a,
- Typeable b,
- Typeable (m a),
- Typeable (m b)
+ Typeable b
)
=> m b -> m a
-mkB = maybe mzero id . cast
+mkB = maybe mzero id . castss
-- | Extend a generic transformation by a type-specific case
-- | Extend a generic monadic transformation by a type-specific case
-extM :: (Typeable a, Typeable b,
- Typeable (m a), Typeable (m b),
- Monad m)
+extM :: ( Monad m,
+ Typeable a,
+ Typeable b
+ )
=> (a -> m a) -> (b -> m b) -> a -> m a
-extM f = maybe f id . cast
+extM f = maybe f id . castarr
-- | Extend a generic MonadPlus transformation by a type-specific case
-extF :: ( MonadPlus m,
- Typeable a,
- Typeable b,
- Typeable (m a),
- Typeable (m b)
- )
- => (a -> m a) -> (b -> m b) -> a -> m a
-extF = extM
+extMp :: ( MonadPlus m,
+ Typeable a,
+ Typeable b
+ )
+ => (a -> m a) -> (b -> m b) -> a -> m a
+extMp = extM
-- | Extend a generic builder by a type-specific case
-extB :: ( Monad m,
- Typeable a,
- Typeable b,
- Typeable (m a),
- Typeable (m b)
+extB :: (Monad m,
+ Typeable a,
+ Typeable b
)
=> m a -> m b -> m a
-extB f = maybe f id . cast
+extB f = maybe f id . castss
------------------------------------------------------------------------------
-}
-- | Choice for monadic transformations
-choiceF :: MonadPlus m => GenericM m -> GenericM m -> GenericM m
-choiceF f g x = f x `mplus` g x
+choiceMp :: MonadPlus m => GenericM m -> GenericM m -> GenericM m
+choiceMp f g x = f x `mplus` g x
-- | Choice for monadic queries
-- | Recover from the failure of monadic transformation by identity
-recoverF :: MonadPlus m => GenericM m -> GenericM m
-recoverF f = f `choiceF` return
+recoverMp :: MonadPlus m => GenericM m -> GenericM m
+recoverMp f = f `choiceMp` return
-- | Recover from the failure of monadic query by a constant