From 576682304c4f358e64129d2e197d5216b4f779be Mon Sep 17 00:00:00 2001 From: ralf Date: Tue, 27 May 2003 09:48:13 +0000 Subject: [PATCH] [project @ 2003-05-27 09:48:13 by ralf] Simplified type of gunfold (removed last arg.) And cosmetics. --- Data/Generics.hs | 59 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/Data/Generics.hs b/Data/Generics.hs index 4be13a7..7de6995 100644 --- a/Data/Generics.hs +++ b/Data/Generics.hs @@ -13,8 +13,11 @@ ----------------------------------------------------------------------------- module Data.Generics ( + +#ifndef __HADDOCK__ -- * Data types for the sum-of-products type encoding (:*:)(..), (:+:)(..), Unit(..), +#endif -- * Typeable and types-save cast Typeable(..), cast, sameType, @@ -32,7 +35,6 @@ module Data.Generics ( extT, extQ, extM, mkTT, - -- * Traversal combinators everything, something, everywhere, everywhereBut, synthesize, branches, undefineds, @@ -121,6 +123,19 @@ mkTT (f::a ->a->a) x y = + +------------------------------------------------------------------- +-- +-- The representation of datatype constructors +-- To be extended by fixity, associativity, and what else? +-- +------------------------------------------------------------------- + +-- | Describes a constructor +data Constr = Constr { conString :: String } + + + --------------------------------------------- -- -- The Data class and its operations @@ -145,12 +160,12 @@ class Typeable a => Data a where -- | Find the constructor conOf :: a -> Constr + -- | Does not look at a; Could live in Typeable as well maybe consOf :: a -> [Constr] gunfold :: (forall a b. Data a => c (a -> b) -> c b) -> (forall g. g -> c g) - -> c a -> Constr -> c a @@ -194,9 +209,6 @@ class Typeable a => Data a where -} --- | Describes a constructor -data Constr = Constr { conString :: String } -- Will be extended - -- | Instructive type synonyms type GenericT = forall a. Data a => a -> a type GenericQ r = forall a. Data a => a -> r @@ -321,7 +333,6 @@ branches = length . gmapQ (const ()) undefineds :: Data a => Constr -> Maybe a undefineds i = gunfold (maybe Nothing (\x -> Just (x undefined))) Just - Nothing i @@ -336,7 +347,9 @@ geq :: forall a. Data a => a -> a -> Bool geq x y = geq' x y where geq' :: forall a b. (Data a, Data b) => a -> b -> Bool - geq' x y = and ( (conString (conOf x) == conString (conOf y)) : tmapQ geq' x y) + geq' x y = and ( (conString (conOf x) == conString (conOf y)) + : tmapQ geq' x y + ) @@ -353,7 +366,10 @@ gzip f x y = -- Generic show gshow :: Data a => a -> String -gshow t = "(" ++ conString (conOf t) ++ concat (gmapQ ((++) " ". gshow) t) ++ ")" +gshow t = "(" + ++ conString (conOf t) + ++ concat (gmapQ ((++) " ". gshow) t) + ++ ")" @@ -370,7 +386,7 @@ gread s guard (not (s' == "")) guard (head s' == '(') (c,s'') <- breakConOf (dropWhile ((==) ' ') (tail s')) - (a,s''') <- unGRead (gunfold f z e c) s'' + (a,s''') <- unGRead (gunfold f z c) s'' guard (not (s''' == "")) guard (head s''' == ')') return (a,tail s''') @@ -379,7 +395,6 @@ gread s (a,s'') <- gread s' return (ab a,s'')) z c = GRead (\s -> Just (c,s)) - e = GRead (const Nothing) -- Get Constr at front @@ -411,18 +426,18 @@ breakConOf s instance Data Float where conOf x = Constr (show x) consOf _ = [] - gunfold f z e c = z (read (conString c)) + gunfold f z c = z (read (conString c)) instance Data Char where conOf x = Constr (show x) consOf _ = [] - gunfold f z e c = z (read (conString c)) + gunfold f z c = z (read (conString c)) {- overlap instance Data String where conOf x = Constr (show x) consOf _ = [] - gunfold f z e = z . read + gunfold f z = z . read -} @@ -430,9 +445,8 @@ instance Data Bool where conOf False = Constr "False" conOf True = Constr "True" consOf _ = [Constr "False",Constr "True"] - gunfold f z e (Constr "False") = z False - gunfold f z e (Constr "True") = z True - gunfold _ _ e _ = e + gunfold f z (Constr "False") = z False + gunfold f z (Constr "True") = z True instance Data a => Data [a] where gmapT f [] = [] @@ -447,9 +461,8 @@ instance Data a => Data [a] where gfoldr f z (x:xs) = f xs (f x (z (:))) conOf [] = Constr "[]" conOf (_:_) = Constr "(:)" - gunfold f z e (Constr "[]") = z [] - gunfold f z e (Constr "(:)") = f (f (z (:))) - gunfold _ _ e _ = e + gunfold f z (Constr "[]") = z [] + gunfold f z (Constr "(:)") = f (f (z (:))) consOf _ = [Constr "[]",Constr "(:)"] @@ -480,9 +493,8 @@ instance Data a => Data [a] where conOf (Box _) = Constr "Box" conOf (Wrap _) = Constr "Wrap" consOf _ = map Constr ["Box","Wrap"] - gunfold f z e "Box" = f (z Box) - gunfold f z e "Wrap" = f (z Wrap) - gunfold _ _ e _ = e + gunfold f z "Box" = f (z Box) + gunfold f z "Wrap" = f (z Wrap) @@ -577,6 +589,3 @@ count f = everything (+) (tick f) -- | Lift a monomorphic predicate to the polymorphic level alike :: (Typeable a, Typeable b) => (a -> Bool) -> b -> Bool alike f = False `mkQ` f - - - -- 1.7.10.4