+
+
+
+------------------------------------------------------------------------------
+--
+-- 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
+ext1T :: (Data d, Typeable1 t)
+ => (forall d. Data d => d -> d)
+ -> (forall d. Data d => t d -> t d)
+ -> d -> d
+ext1T def ext = unT ((T def) `ext1` (T ext))
+
+
+-- | Type extension of monadic transformations for type constructors
+ext1M :: (Monad m, Data d, Typeable1 t)
+ => (forall d. Data d => d -> m d)
+ -> (forall d. Data d => t d -> m (t d))
+ -> d -> m d
+ext1M def ext = unM ((M def) `ext1` (M ext))
+
+
+-- | Type extension of queries for type constructors
+ext1Q :: (Data d, Typeable1 t)
+ => (d -> q)
+ -> (forall d. Data d => t d -> q)
+ -> d -> q
+ext1Q def ext = unQ ((Q def) `ext1` (Q ext))
+
+
+-- | Type extension of readers for type constructors
+ext1R :: (Monad m, Data d, Typeable1 t)
+ => m d
+ -> (forall d. Data d => m (t d))
+ -> m d
+ext1R def ext = unR ((R def) `ext1` (R ext))
+
+
+
+------------------------------------------------------------------------------
+--
+-- Type constructors for type-level lambdas
+--
+------------------------------------------------------------------------------
+
+
+-- | The type constructor for transformations
+newtype T x = T { unT :: x -> x }
+
+-- | The type constructor for transformations
+newtype M m x = M { unM :: x -> m x }
+
+-- | The type constructor for queries
+newtype Q q x = Q { unQ :: x -> q }
+
+-- | The type constructor for readers
+newtype R m x = R { unR :: m x }