[project @ 2003-09-24 10:41:11 by simonmar]
[haskell-directory.git] / Data / Generics / Aliases.hs
index ceb70c9..b1bcd96 100644 (file)
@@ -8,16 +8,18 @@
 -- 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, 
@@ -31,9 +33,9 @@ module Data.Generics.Aliases (
        orElse,
 
        -- * Function combinators on generic functions
-       recoverF,
+       recoverMp,
        recoverQ,
-       choiceF,
+       choiceMp,
        choiceQ
 
   ) where
@@ -76,13 +78,11 @@ mkQ :: (Typeable a, Typeable b) => r -> (b -> r) -> a -> r
 --   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
 
@@ -99,14 +99,12 @@ use a point-free style whenever possible.
 -- | 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;
@@ -115,12 +113,10 @@ mkF = maybe (const mzero) id . cast
 --
 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
@@ -134,34 +130,31 @@ extQ f g a = maybe (f a) g (cast a)
 
 
 -- | 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
 
 
 ------------------------------------------------------------------------------
@@ -229,8 +222,8 @@ queries a given constant is returned.
 -}
 
 -- | 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
@@ -239,8 +232,8 @@ choiceQ f g x = f x `mplus` g x
 
 
 -- | 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