From fbc83401e9196b75601ab3f6c13e6c83e0b39f31 Mon Sep 17 00:00:00 2001 From: ralf Date: Thu, 26 Feb 2004 18:06:52 +0000 Subject: [PATCH] [project @ 2004-02-26 18:06:51 by ralf] Simplified kind-polymorphic boilerplate stuff. --- Data/Generics/Aliases.hs | 9 +++++++++ Data/Generics/Basics.hs | 39 ++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Data/Generics/Aliases.hs b/Data/Generics/Aliases.hs index 3c03f56..3c66298 100644 --- a/Data/Generics/Aliases.hs +++ b/Data/Generics/Aliases.hs @@ -336,6 +336,15 @@ gunfoldR c f = gmapM (const f) $ fromConstr c ------------------------------------------------------------------------------ + +-- | 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 (cast0to1 ext) + + -- | Type extension of transformations for unary type constructors ext1T :: (Data d, Typeable1 t) => (forall d. Data d => d -> d) diff --git a/Data/Generics/Basics.hs b/Data/Generics/Basics.hs index e7c8c76..89738d3 100644 --- a/Data/Generics/Basics.hs +++ b/Data/Generics/Basics.hs @@ -25,8 +25,8 @@ module Data.Generics.Basics ( toConstr, -- :: a -> Constr fromConstr, -- :: Constr -> a dataTypeOf, -- :: a -> DataType - ext1, -- type extension for unary type constructors - ext2 -- type extension for binary type constructors + cast0to1, -- mediate types and unary type constructors + cast0to2 -- mediate types and binary type constructors ), -- * Constructor representations @@ -145,25 +145,23 @@ fold. ------------------------------------------------------------------------------ -- --- Type extension for unary and binary type constructors +-- Mediate types and type constructors -- ------------------------------------------------------------------------------ - -- | Type extension for unary type constructors - ext1 :: Typeable1 t - => c a - -> (forall a. Data a => c (t a)) - -> c a + -- | Mediate types and unary type constructors + cast0to1 :: Typeable1 t + => (forall a. Data a => c (t a)) + -> Maybe (c a) + cast0to1 _ = Nothing - ext1 def ext = def + -- | Mediate types and binary type constructors + cast0to2 :: Typeable2 t + => (forall a b. (Data a, Data b) => c (t a b)) + -> Maybe (c a) + cast0to2 _ = Nothing - -- | Type extension for binary type constructors - ext2 :: Typeable2 t - => c a - -> (forall a b. (Data a, Data b) => c (t a b)) -> c a - ext2 def ext = def - ------------------------------------------------------------------------------ -- @@ -578,8 +576,7 @@ instance Data a => Data [a] where 1 -> [] 2 -> undefined:undefined dataTypeOf _ = listDataType - ext1 def ext = maybe def id (cast1 ext) - + cast0to1 = cast1 -- -- The gmaps are given as an illustration. @@ -611,7 +608,7 @@ instance Data a => Data (Maybe a) where 1 -> Nothing 2 -> Just undefined dataTypeOf _ = maybeDataType - ext1 def ext = maybe def id (cast1 ext) + cast0to1 = cast1 -- @@ -628,7 +625,7 @@ instance (Data a, Data b) => Data (a,b) where fromConstr c = case conIndex c of 1 -> (undefined,undefined) dataTypeOf _ = productDataType - ext2 def ext = maybe def id (cast2 ext) + cast0to2 = cast2 -- @@ -675,7 +672,7 @@ instance (Data a, Data b) => Data (Either a b) where 1 -> Left undefined 2 -> Right undefined dataTypeOf _ = eitherDataType - ext2 def ext = maybe def id (cast2 ext) + cast0to2 = cast2 {- @@ -703,4 +700,4 @@ instance (Data a, Data b) => Data (a -> b) where toConstr _ = FunConstr fromConstr _ = undefined dataTypeOf _ = FunType - ext2 def ext = maybe def id (cast2 ext) + cast0to2 = cast2 -- 1.7.10.4