-----------------------------------------------------------------------------
-- |
-- Module : Data.Generics.Twins
--- Copyright : (c) The University of Glasgow, CWI 2001--2003
+-- Copyright : (c) The University of Glasgow, CWI 2001--2004
-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- 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
import Data.Generics.Basics
import Data.Generics.Aliases
+#ifdef __GLASGOW_HASKELL__
+import Prelude hiding ( GT )
+#endif
+
------------------------------------------------------------------------------
-- | A type constructor for accumulation
-newtype A a c d = A (a -> (a, c d))
-unA (A f) = f
+newtype A a c d = A { unA :: a -> (a, c d) }
-- | gmapT with accumulation
z a x = (a, ID x)
--- | gmapT with accumulation
+-- | gmapM with accumulation
gmapAccumM :: (Data d, Monad m)
=> (forall d. Data d => a -> d -> (a, m d))
-> a -> d -> (a, m d)
([], c) -> c
_ -> error "gzipWithT"
where
- perkid a d = (tail a, unGenericT' (head a) d)
- funs = gmapQ (\k -> GenericT' (f k)) x
+ perkid a d = (tail a, unGT (head a) d)
+ funs = gmapQ (\k -> GT (f k)) x
([], c) -> c
_ -> error "gzipWithM"
where
- perkid a d = (tail a, unGenericM' (head a) d)
- funs = gmapQ (\k -> GenericM' (f k)) x
+ perkid a d = (tail a, unGM (head a) d)
+ funs = gmapQ (\k -> GM (f k)) x
--- | Twin map for monadic transformation
+-- | Twin map for queries
gzipWithQ :: GenericQ (GenericQ r) -> GenericQ (GenericQ [r])
gzipWithQ f x y = case gmapAccumQ perkid funs y of
([], r) -> r
_ -> error "gzipWithQ"
where
- perkid a d = (tail a, unGenericQ' (head a) d)
- funs = gmapQ (\k -> GenericQ' (f k)) x
+ perkid a d = (tail a, unGQ (head a) d)
+ funs = gmapQ (\k -> GQ (f k)) x