From 02c5c7a53971f3f5387499e7862608b787cf2a6f Mon Sep 17 00:00:00 2001 From: Don Stewart Date: Tue, 4 Mar 2008 22:51:20 +0000 Subject: [PATCH] untabify --- Data/Generics/Aliases.hs | 64 ++++----- Data/Generics/Basics.hs | 344 ++++++++++++++++++++++---------------------- Data/Generics/Instances.hs | 25 ++-- Data/Generics/Schemes.hs | 24 ++-- Data/Generics/Text.hs | 38 ++--- Data/Generics/Twins.hs | 62 ++++---- 6 files changed, 277 insertions(+), 280 deletions(-) diff --git a/Data/Generics/Aliases.hs b/Data/Generics/Aliases.hs index c37a98b..024c3de 100644 --- a/Data/Generics/Aliases.hs +++ b/Data/Generics/Aliases.hs @@ -15,38 +15,38 @@ -- ----------------------------------------------------------------------------- -module Data.Generics.Aliases ( - - -- * Combinators to \"make\" generic functions via cast - mkT, mkQ, mkM, mkMp, mkR, - ext0, extT, extQ, extM, extMp, extB, extR, - - -- * Type synonyms for generic function types - GenericT, - GenericQ, - GenericM, - GenericB, - GenericR, +module Data.Generics.Aliases ( + + -- * Combinators to \"make\" generic functions via cast + mkT, mkQ, mkM, mkMp, mkR, + ext0, extT, extQ, extM, extMp, extB, extR, + + -- * Type synonyms for generic function types + GenericT, + GenericQ, + GenericM, + GenericB, + GenericR, Generic, Generic'(..), GenericT'(..), GenericQ'(..), GenericM'(..), - -- * Inredients of generic functions - orElse, + -- * Inredients of generic functions + orElse, - -- * Function combinators on generic functions - recoverMp, - recoverQ, - choiceMp, - choiceQ, + -- * Function combinators on generic functions + recoverMp, + recoverQ, + choiceMp, + choiceQ, - -- * Type extension for unary type constructors - ext1T, - ext1M, - ext1Q, - ext1R + -- * Type extension for unary type constructors + ext1T, + ext1M, + ext1Q, + ext1R ) where @@ -58,8 +58,8 @@ import Data.Generics.Basics ------------------------------------------------------------------------------ -- --- Combinators to "make" generic functions --- We use type-safe cast in a number of ways to make generic functions. +-- Combinators to "make" generic functions +-- We use type-safe cast in a number of ways to make generic functions. -- ------------------------------------------------------------------------------ @@ -71,7 +71,7 @@ mkT :: ( Typeable a , Typeable b ) => (b -> b) - -> a + -> a -> a mkT = extT id @@ -85,7 +85,7 @@ mkQ :: ( Typeable a ) => r -> (b -> r) - -> a + -> a -> r (r `mkQ` br) a = case cast a of Just b -> br b @@ -101,7 +101,7 @@ mkM :: ( Monad m , Typeable b ) => (b -> m b) - -> a + -> a -> m a mkM = extM return @@ -205,7 +205,7 @@ extR def ext = unR ((R def) `ext0` (R ext)) ------------------------------------------------------------------------------ -- --- Type synonyms for generic function types +-- Type synonyms for generic function types -- ------------------------------------------------------------------------------ @@ -301,7 +301,7 @@ recoverQ r f = f `choiceQ` const (return r) ------------------------------------------------------------------------------ -- --- Type extension for unary type constructors +-- Type extension for unary type constructors -- ------------------------------------------------------------------------------ @@ -350,7 +350,7 @@ ext1R def ext = unR ((R def) `ext1` (R ext)) ------------------------------------------------------------------------------ -- --- Type constructors for type-level lambdas +-- Type constructors for type-level lambdas -- ------------------------------------------------------------------------------ diff --git a/Data/Generics/Basics.hs b/Data/Generics/Basics.hs index e9c59f6..ac3cdde 100644 --- a/Data/Generics/Basics.hs +++ b/Data/Generics/Basics.hs @@ -14,79 +14,79 @@ -- ----------------------------------------------------------------------------- -module Data.Generics.Basics ( - - -- * Module Data.Typeable re-exported for convenience - module Data.Typeable, - - -- * The Data class for processing constructor applications - Data( - gfoldl, -- :: ... -> a -> c a - gunfold, -- :: ... -> Constr -> c a - toConstr, -- :: a -> Constr - dataTypeOf, -- :: a -> DataType - dataCast1, -- mediate types and unary type constructors - dataCast2, -- mediate types and binary type constructors - -- Generic maps defined in terms of gfoldl - gmapT, - gmapQ, - gmapQl, - gmapQr, - gmapQi, - gmapM, - gmapMp, - gmapMo +module Data.Generics.Basics ( + + -- * Module Data.Typeable re-exported for convenience + module Data.Typeable, + + -- * The Data class for processing constructor applications + Data( + gfoldl, -- :: ... -> a -> c a + gunfold, -- :: ... -> Constr -> c a + toConstr, -- :: a -> Constr + dataTypeOf, -- :: a -> DataType + dataCast1, -- mediate types and unary type constructors + dataCast2, -- mediate types and binary type constructors + -- Generic maps defined in terms of gfoldl + gmapT, + gmapQ, + gmapQl, + gmapQr, + gmapQi, + gmapM, + gmapMp, + gmapMo ), - -- * Datatype representations - DataType, -- abstract, instance of: Show - -- ** Constructors - mkDataType, -- :: String -> [Constr] -> DataType - mkIntType, -- :: String -> DataType - mkFloatType, -- :: String -> DataType - mkStringType, -- :: String -> DataType - mkNorepType, -- :: String -> DataType - -- ** Observers - dataTypeName, -- :: DataType -> String - DataRep(..), -- instance of: Eq, Show - dataTypeRep, -- :: DataType -> DataRep - -- ** Convenience functions - repConstr, -- :: DataType -> ConstrRep -> Constr - isAlgType, -- :: DataType -> Bool - dataTypeConstrs,-- :: DataType -> [Constr] - indexConstr, -- :: DataType -> ConIndex -> Constr - maxConstrIndex, -- :: DataType -> ConIndex - isNorepType, -- :: DataType -> Bool - - -- * Data constructor representations - Constr, -- abstract, instance of: Eq, Show - ConIndex, -- alias for Int, start at 1 - Fixity(..), -- instance of: Eq, Show - -- ** Constructors - mkConstr, -- :: DataType -> String -> Fixity -> Constr - mkIntConstr, -- :: DataType -> Integer -> Constr - mkFloatConstr, -- :: DataType -> Double -> Constr - mkStringConstr, -- :: DataType -> String -> Constr - -- ** Observers - constrType, -- :: Constr -> DataType - ConstrRep(..), -- instance of: Eq, Show - constrRep, -- :: Constr -> ConstrRep - constrFields, -- :: Constr -> [String] - constrFixity, -- :: Constr -> Fixity - -- ** Convenience function: algebraic data types - constrIndex, -- :: Constr -> ConIndex - -- ** From strings to constructors and vice versa: all data types - showConstr, -- :: Constr -> String - readConstr, -- :: DataType -> String -> Maybe Constr - - -- * Convenience functions: take type constructors apart - tyconUQname, -- :: String -> String - tyconModule, -- :: String -> String - - -- * Generic operations defined in terms of 'gunfold' - fromConstr, -- :: Constr -> a - fromConstrB, -- :: ... -> Constr -> a - fromConstrM -- :: Monad m => ... -> Constr -> m a + -- * Datatype representations + DataType, -- abstract, instance of: Show + -- ** Constructors + mkDataType, -- :: String -> [Constr] -> DataType + mkIntType, -- :: String -> DataType + mkFloatType, -- :: String -> DataType + mkStringType, -- :: String -> DataType + mkNorepType, -- :: String -> DataType + -- ** Observers + dataTypeName, -- :: DataType -> String + DataRep(..), -- instance of: Eq, Show + dataTypeRep, -- :: DataType -> DataRep + -- ** Convenience functions + repConstr, -- :: DataType -> ConstrRep -> Constr + isAlgType, -- :: DataType -> Bool + dataTypeConstrs,-- :: DataType -> [Constr] + indexConstr, -- :: DataType -> ConIndex -> Constr + maxConstrIndex, -- :: DataType -> ConIndex + isNorepType, -- :: DataType -> Bool + + -- * Data constructor representations + Constr, -- abstract, instance of: Eq, Show + ConIndex, -- alias for Int, start at 1 + Fixity(..), -- instance of: Eq, Show + -- ** Constructors + mkConstr, -- :: DataType -> String -> Fixity -> Constr + mkIntConstr, -- :: DataType -> Integer -> Constr + mkFloatConstr, -- :: DataType -> Double -> Constr + mkStringConstr, -- :: DataType -> String -> Constr + -- ** Observers + constrType, -- :: Constr -> DataType + ConstrRep(..), -- instance of: Eq, Show + constrRep, -- :: Constr -> ConstrRep + constrFields, -- :: Constr -> [String] + constrFixity, -- :: Constr -> Fixity + -- ** Convenience function: algebraic data types + constrIndex, -- :: Constr -> ConIndex + -- ** From strings to constructors and vice versa: all data types + showConstr, -- :: Constr -> String + readConstr, -- :: DataType -> String -> Maybe Constr + + -- * Convenience functions: take type constructors apart + tyconUQname, -- :: String -> String + tyconModule, -- :: String -> String + + -- * Generic operations defined in terms of 'gunfold' + fromConstr, -- :: Constr -> a + fromConstrB, -- :: ... -> Constr -> a + fromConstrM -- :: Monad m => ... -> Constr -> m a ) where @@ -103,7 +103,7 @@ import Control.Monad ------------------------------------------------------------------------------ -- --- The Data class +-- The Data class -- ------------------------------------------------------------------------------ @@ -186,20 +186,20 @@ class Typeable a => Data a where -- The default definition for 'gfoldl' is @'const' 'id'@, which is -- suitable for abstract datatypes with no substructures. gfoldl :: (forall a b. Data a => c (a -> b) -> a -> c b) - -- ^ defines how nonempty constructor applications are - -- folded. It takes the folded tail of the constructor - -- application and its head, i.e., an immediate subterm, - -- and combines them in some way. + -- ^ defines how nonempty constructor applications are + -- folded. It takes the folded tail of the constructor + -- application and its head, i.e., an immediate subterm, + -- and combines them in some way. -> (forall g. g -> c g) - -- ^ defines how the empty constructor application is - -- folded, like the neutral \/ start element for list - -- folding. + -- ^ defines how the empty constructor application is + -- folded, like the neutral \/ start element for list + -- folding. -> a - -- ^ structure to be folded. - -> c a - -- ^ result, with a type defined in terms of @a@, but - -- variability is achieved by means of type constructor - -- @c@ for the construction of the actual result type. + -- ^ structure to be folded. + -> c a + -- ^ result, with a type defined in terms of @a@, but + -- variability is achieved by means of type constructor + -- @c@ for the construction of the actual result type. -- See the 'Data' instances in this file for an illustration of 'gfoldl'. @@ -255,7 +255,7 @@ class Typeable a => Data a where ------------------------------------------------------------------------------ -- --- Typical generic maps defined in terms of gfoldl +-- Typical generic maps defined in terms of gfoldl -- ------------------------------------------------------------------------------ @@ -280,7 +280,7 @@ class Typeable a => Data a where gmapQl :: (r -> r' -> r) -> r -> (forall a. Data a => a -> r') -> a -> r gmapQl o r f = unCONST . gfoldl k z where - k c x = CONST $ (unCONST c) `o` f x + k c x = CONST $ (unCONST c) `o` f x z _ = CONST r -- | A generic query with a right-associative binary operator @@ -299,9 +299,9 @@ class Typeable a => Data a where -- | A generic query that processes one child by index (zero-based) gmapQi :: Int -> (forall a. Data a => a -> u) -> a -> u - gmapQi i f x = case gfoldl k z x of { Qi _ q -> fromJust q } + gmapQi i f x = case gfoldl k z x of { Qi _ q -> fromJust q } where - k (Qi i' q) a = Qi (i'+1) (if i==i' then Just (f a) else q) + k (Qi i' q) a = Qi (i'+1) (if i==i' then Just (f a) else q) z f = Qi 0 Nothing @@ -339,7 +339,7 @@ this end, we couple the monadic computation with a Boolean. where z g = Mp (return (g,False)) k (Mp c) x - = Mp ( c >>= \(h,b) -> + = Mp ( c >>= \(h,b) -> (f x >>= \x' -> return (h x',True)) `mplus` return (h x,b) ) @@ -362,7 +362,7 @@ was transformed successfully. where z g = Mp (return (g,False)) k (Mp c) x - = Mp ( c >>= \(h,b) -> if b + = Mp ( c >>= \(h,b) -> if b then return (h x,b) else (f x >>= \x' -> return (h x',True)) `mplus` return (h x,b) @@ -392,7 +392,7 @@ newtype Mp m x = Mp { unMp :: m (x, Bool) } ------------------------------------------------------------------------------ -- --- Generic unfolding +-- Generic unfolding -- ------------------------------------------------------------------------------ @@ -418,7 +418,7 @@ fromConstrM :: (Monad m, Data a) => (forall a. Data a => m a) -> Constr -> m a -fromConstrM f = gunfold k z +fromConstrM f = gunfold k z where k c = do { c' <- c; b <- f; return (c' b) } z = return @@ -427,7 +427,7 @@ fromConstrM f = gunfold k z ------------------------------------------------------------------------------ -- --- Datatype and constructor representations +-- Datatype and constructor representations -- ------------------------------------------------------------------------------ @@ -437,21 +437,21 @@ fromConstrM f = gunfold k z -- A package of constructor representations with names of type and module. -- data DataType = DataType - { tycon :: String - , datarep :: DataRep - } + { tycon :: String + , datarep :: DataRep + } deriving Show -- | Representation of constructors data Constr = Constr - { conrep :: ConstrRep - , constring :: String - , confields :: [String] -- for AlgRep only - , confixity :: Fixity -- for AlgRep only - , datatype :: DataType - } + { conrep :: ConstrRep + , constring :: String + , confields :: [String] -- for AlgRep only + , confixity :: Fixity -- for AlgRep only + , datatype :: DataType + } instance Show Constr where show = constring @@ -465,21 +465,21 @@ instance Eq Constr where -- | Public representation of datatypes data DataRep = AlgRep [Constr] | IntRep - | FloatRep - | StringRep + | FloatRep + | StringRep | NoRep - deriving (Eq,Show) + deriving (Eq,Show) -- The list of constructors could be an array, a balanced tree, or others. -- | Public representation of constructors data ConstrRep = AlgConstr ConIndex | IntConstr Integer - | FloatConstr Double - | StringConstr String + | FloatConstr Double + | StringConstr String - deriving (Eq,Show) + deriving (Eq,Show) -- | Unique index for datatype constructors, @@ -489,14 +489,14 @@ type ConIndex = Int -- | Fixity of constructors data Fixity = Prefix - | Infix -- Later: add associativity and precedence + | Infix -- Later: add associativity and precedence - deriving (Eq,Show) + deriving (Eq,Show) ------------------------------------------------------------------------------ -- --- Observers for datatype representations +-- Observers for datatype representations -- ------------------------------------------------------------------------------ @@ -526,17 +526,17 @@ constrRep = conrep repConstr :: DataType -> ConstrRep -> Constr repConstr dt cr = case (dataTypeRep dt, cr) of - (AlgRep cs, AlgConstr i) -> cs !! (i-1) - (IntRep, IntConstr i) -> mkIntConstr dt i - (FloatRep, FloatConstr f) -> mkFloatConstr dt f - (StringRep, StringConstr str) -> mkStringConstr dt str - _ -> error "repConstr" + (AlgRep cs, AlgConstr i) -> cs !! (i-1) + (IntRep, IntConstr i) -> mkIntConstr dt i + (FloatRep, FloatConstr f) -> mkFloatConstr dt f + (StringRep, StringConstr str) -> mkStringConstr dt str + _ -> error "repConstr" ------------------------------------------------------------------------------ -- --- Representations of algebraic data types +-- Representations of algebraic data types -- ------------------------------------------------------------------------------ @@ -544,21 +544,21 @@ repConstr dt cr = -- | Constructs an algebraic datatype mkDataType :: String -> [Constr] -> DataType mkDataType str cs = DataType - { tycon = str - , datarep = AlgRep cs - } + { tycon = str + , datarep = AlgRep cs + } -- | Constructs a constructor mkConstr :: DataType -> String -> [String] -> Fixity -> Constr mkConstr dt str fields fix = - Constr - { conrep = AlgConstr idx - , constring = str - , confields = fields - , confixity = fix - , datatype = dt - } + Constr + { conrep = AlgConstr idx + , constring = str + , confields = fields + , confixity = fix + , datatype = dt + } where idx = head [ i | (c,i) <- dataTypeConstrs dt `zip` [1..], showConstr c == str ] @@ -566,9 +566,9 @@ mkConstr dt str fields fix = -- | Gets the constructors of an algebraic datatype dataTypeConstrs :: DataType -> [Constr] -dataTypeConstrs dt = case datarep dt of - (AlgRep cons) -> cons - _ -> error "dataTypeConstrs" +dataTypeConstrs dt = case datarep dt of + (AlgRep cons) -> cons + _ -> error "dataTypeConstrs" -- | Gets the field labels of a constructor. The list of labels @@ -586,8 +586,8 @@ constrFixity = confixity ------------------------------------------------------------------------------ -- --- From strings to constr's and vice versa: all data types --- +-- From strings to constr's and vice versa: all data types +-- ------------------------------------------------------------------------------ @@ -600,22 +600,22 @@ showConstr = constring readConstr :: DataType -> String -> Maybe Constr readConstr dt str = case dataTypeRep dt of - AlgRep cons -> idx cons - IntRep -> mkReadCon (\i -> (mkPrimCon dt str (IntConstr i))) - FloatRep -> mkReadCon (\f -> (mkPrimCon dt str (FloatConstr f))) - StringRep -> Just (mkStringConstr dt str) + AlgRep cons -> idx cons + IntRep -> mkReadCon (\i -> (mkPrimCon dt str (IntConstr i))) + FloatRep -> mkReadCon (\f -> (mkPrimCon dt str (FloatConstr f))) + StringRep -> Just (mkStringConstr dt str) NoRep -> Nothing where -- Read a value and build a constructor mkReadCon :: Read t => (t -> Constr) -> Maybe Constr mkReadCon f = case (reads str) of - [(t,"")] -> Just (f t) - _ -> Nothing + [(t,"")] -> Just (f t) + _ -> Nothing -- Traverse list of algebraic datatype constructors idx :: [Constr] -> Maybe Constr - idx cons = let fit = filter ((==) str . showConstr) cons + idx cons = let fit = filter ((==) str . showConstr) cons in if fit == [] then Nothing else Just (head fit) @@ -623,7 +623,7 @@ readConstr dt str = ------------------------------------------------------------------------------ -- --- Convenience funtions: algebraic data types +-- Convenience funtions: algebraic data types -- ------------------------------------------------------------------------------ @@ -631,35 +631,35 @@ readConstr dt str = -- | Test for an algebraic type isAlgType :: DataType -> Bool isAlgType dt = case datarep dt of - (AlgRep _) -> True - _ -> False + (AlgRep _) -> True + _ -> False -- | Gets the constructor for an index (algebraic datatypes only) indexConstr :: DataType -> ConIndex -> Constr indexConstr dt idx = case datarep dt of - (AlgRep cs) -> cs !! (idx-1) - _ -> error "indexConstr" + (AlgRep cs) -> cs !! (idx-1) + _ -> error "indexConstr" -- | Gets the index of a constructor (algebraic datatypes only) constrIndex :: Constr -> ConIndex constrIndex con = case constrRep con of (AlgConstr idx) -> idx - _ -> error "constrIndex" + _ -> error "constrIndex" -- | Gets the maximum constructor index of an algebraic datatype maxConstrIndex :: DataType -> ConIndex maxConstrIndex dt = case dataTypeRep dt of - AlgRep cs -> length cs - _ -> error "maxConstrIndex" + AlgRep cs -> length cs + _ -> error "maxConstrIndex" ------------------------------------------------------------------------------ -- --- Representation of primitive types +-- Representation of primitive types -- ------------------------------------------------------------------------------ @@ -682,43 +682,43 @@ mkStringType = mkPrimType StringRep -- | Helper for 'mkIntType', 'mkFloatType', 'mkStringType' mkPrimType :: DataRep -> String -> DataType mkPrimType dr str = DataType - { tycon = str - , datarep = dr - } + { tycon = str + , datarep = dr + } -- Makes a constructor for primitive types mkPrimCon :: DataType -> String -> ConstrRep -> Constr -mkPrimCon dt str cr = Constr - { datatype = dt - , conrep = cr - , constring = str - , confields = error "constrFields" - , confixity = error "constrFixity" - } +mkPrimCon dt str cr = Constr + { datatype = dt + , conrep = cr + , constring = str + , confields = error "constrFields" + , confixity = error "constrFixity" + } mkIntConstr :: DataType -> Integer -> Constr mkIntConstr dt i = case datarep dt of - IntRep -> mkPrimCon dt (show i) (IntConstr i) - _ -> error "mkIntConstr" + IntRep -> mkPrimCon dt (show i) (IntConstr i) + _ -> error "mkIntConstr" mkFloatConstr :: DataType -> Double -> Constr mkFloatConstr dt f = case datarep dt of - FloatRep -> mkPrimCon dt (show f) (FloatConstr f) - _ -> error "mkFloatConstr" + FloatRep -> mkPrimCon dt (show f) (FloatConstr f) + _ -> error "mkFloatConstr" mkStringConstr :: DataType -> String -> Constr mkStringConstr dt str = case datarep dt of - StringRep -> mkPrimCon dt str (StringConstr str) - _ -> error "mkStringConstr" + StringRep -> mkPrimCon dt str (StringConstr str) + _ -> error "mkStringConstr" ------------------------------------------------------------------------------ -- --- Non-representations for non-presentable types +-- Non-representations for non-presentable types -- ------------------------------------------------------------------------------ @@ -726,22 +726,22 @@ mkStringConstr dt str = case datarep dt of -- | Constructs a non-representation for a non-presentable type mkNorepType :: String -> DataType mkNorepType str = DataType - { tycon = str - , datarep = NoRep - } + { tycon = str + , datarep = NoRep + } -- | Test for a non-representable type isNorepType :: DataType -> Bool isNorepType dt = case datarep dt of - NoRep -> True - _ -> False + NoRep -> True + _ -> False ------------------------------------------------------------------------------ -- --- Convenience for qualified type constructors +-- Convenience for qualified type constructors -- ------------------------------------------------------------------------------ @@ -759,7 +759,7 @@ tyconUQname x = let x' = dropWhile (not . (==) '.') x tyconModule :: String -> String tyconModule x = let (a,b) = break ((==) '.') x in if b == "" - then b + then b else a ++ tyconModule' (tail b) where tyconModule' x = let x' = tyconModule x diff --git a/Data/Generics/Instances.hs b/Data/Generics/Instances.hs index 75de715..0745b05 100644 --- a/Data/Generics/Instances.hs +++ b/Data/Generics/Instances.hs @@ -15,9 +15,7 @@ -- ----------------------------------------------------------------------------- -module Data.Generics.Instances - -where +module Data.Generics.Instances where ------------------------------------------------------------------------------ @@ -32,22 +30,21 @@ import Data.Typeable import Data.Int -- So we can give Data instance for Int8, ... import Data.Word -- So we can give Data instance for Word8, ... import GHC.Real( Ratio(..) ) -- So we can give Data instance for Ratio -import GHC.IOBase -- So we can give Data instance for IO, Handle -import GHC.Ptr -- So we can give Data instance for Ptr -import GHC.ForeignPtr -- So we can give Data instance for ForeignPtr -import GHC.Stable -- So we can give Data instance for StablePtr -import GHC.ST -- So we can give Data instance for ST -import GHC.Conc -- So we can give Data instance for MVar & Co. -import GHC.Arr -- So we can give Data instance for Array +import GHC.IOBase -- So we can give Data instance for IO, Handle +import GHC.Ptr -- So we can give Data instance for Ptr +import GHC.ForeignPtr -- So we can give Data instance for ForeignPtr +import GHC.Stable -- So we can give Data instance for StablePtr +import GHC.ST -- So we can give Data instance for ST +import GHC.Conc -- So we can give Data instance for MVar & Co. +import GHC.Arr -- So we can give Data instance for Array #include "Typeable.h" - ------------------------------------------------------------------------------ -- --- Instances of the Data class for Prelude-like types. --- We define top-level definitions for representations. +-- Instances of the Data class for Prelude-like types. +-- We define top-level definitions for representations. -- ------------------------------------------------------------------------------ @@ -378,7 +375,7 @@ tuple0DataType = mkDataType "Prelude.()" [tuple0Constr] instance Data () where toConstr () = tuple0Constr - gunfold k z c | constrIndex c == 1 = z () + gunfold k z c | constrIndex c == 1 = z () gunfold _ _ _ = error "gunfold" dataTypeOf _ = tuple0DataType diff --git a/Data/Generics/Schemes.hs b/Data/Generics/Schemes.hs index f23bcd0..4e75a82 100644 --- a/Data/Generics/Schemes.hs +++ b/Data/Generics/Schemes.hs @@ -14,24 +14,24 @@ -- ----------------------------------------------------------------------------- -module Data.Generics.Schemes ( +module Data.Generics.Schemes ( everywhere, everywhere', everywhereBut, everywhereM, somewhere, - everything, - listify, + everything, + listify, something, - synthesize, - gsize, - glength, - gdepth, - gcount, - gnodecount, - gtypecount, - gfindtype + synthesize, + gsize, + glength, + gdepth, + gcount, + gnodecount, + gtypecount, + gfindtype ) where @@ -98,7 +98,7 @@ everything :: (r -> r -> r) -> GenericQ r -> GenericQ r -- use gmapQ to recurse into immediate subterms; -- use ordinary foldl to reduce list of intermediate results -- -everything k f x +everything k f x = foldl k (f x) (gmapQ (everything k f) x) diff --git a/Data/Generics/Text.hs b/Data/Generics/Text.hs index 5a81cc1..0137c36 100644 --- a/Data/Generics/Text.hs +++ b/Data/Generics/Text.hs @@ -14,10 +14,10 @@ -- ----------------------------------------------------------------------------- -module Data.Generics.Text ( +module Data.Generics.Text ( - gshow, - gread + gshow, + gread ) where @@ -86,39 +86,39 @@ gread = readP_to_S gread' -- The generic default for gread allButString = do - -- Drop " ( " - skipSpaces -- Discard leading space - char '(' -- Parse '(' - skipSpaces -- Discard following space - - -- Do the real work - str <- parseConstr -- Get a lexeme for the constructor - con <- str2con str -- Convert it to a Constr (may fail) + -- Drop " ( " + skipSpaces -- Discard leading space + char '(' -- Parse '(' + skipSpaces -- Discard following space + + -- Do the real work + str <- parseConstr -- Get a lexeme for the constructor + con <- str2con str -- Convert it to a Constr (may fail) x <- fromConstrM gread' con -- Read the children - -- Drop " ) " - skipSpaces -- Discard leading space - char ')' -- Parse ')' - skipSpaces -- Discard following space + -- Drop " ) " + skipSpaces -- Discard leading space + char ')' -- Parse ')' + skipSpaces -- Discard following space return x -- Turn string into constructor driven by the requested result type, -- failing in the monad if it isn't a constructor of this data type - str2con :: String -> ReadP Constr + str2con :: String -> ReadP Constr str2con = maybe mzero return . readConstr myDataType -- Get a Constr's string at the front of an input string parseConstr :: ReadP String - parseConstr = + parseConstr = string "[]" -- Compound lexeme "[]" - <++ infixOp -- Infix operator in parantheses + <++ infixOp -- Infix operator in parantheses <++ readS_to_P lex -- Ordinary constructors and literals -- Handle infix operators such as (:) infixOp :: ReadP String infixOp = do c1 <- char '(' str <- munch1 (not . (==) ')') - c2 <- char ')' + c2 <- char ')' return $ [c1] ++ str ++ [c2] diff --git a/Data/Generics/Twins.hs b/Data/Generics/Twins.hs index eed4ab6..4045c2e 100644 --- a/Data/Generics/Twins.hs +++ b/Data/Generics/Twins.hs @@ -15,24 +15,24 @@ -- ----------------------------------------------------------------------------- -module Data.Generics.Twins ( +module Data.Generics.Twins ( - -- * Generic folds and maps that also accumulate - gfoldlAccum, - gmapAccumT, - gmapAccumM, - gmapAccumQl, - gmapAccumQr, - gmapAccumQ, + -- * Generic folds and maps that also accumulate + gfoldlAccum, + gmapAccumT, + gmapAccumM, + gmapAccumQl, + gmapAccumQr, + gmapAccumQ, - -- * Mapping combinators for twin traversal - gzipWithT, - gzipWithM, - gzipWithQ, + -- * Mapping combinators for twin traversal + gzipWithT, + gzipWithM, + gzipWithQ, - -- * Typical twin traversals - geq, - gzip + -- * Typical twin traversals + geq, + gzip ) where @@ -54,7 +54,7 @@ import Prelude hiding ( GT ) ------------------------------------------------------------------------------ -- --- Generic folds and maps that also accumulate +-- Generic folds and maps that also accumulate -- ------------------------------------------------------------------------------ @@ -97,7 +97,7 @@ gmapAccumT :: Data d gmapAccumT f a d = let (a',d') = gfoldlAccum k z a d in (a',unID d') where - k a (ID c) d = let (a',d') = f a d + k a (ID c) d = let (a',d') = f a d in (a', ID (c d')) z a x = (a, ID x) @@ -108,35 +108,35 @@ gmapAccumM :: (Data d, Monad m) -> a -> d -> (a, m d) gmapAccumM f = gfoldlAccum k z where - k a c d = let (a',d') = f a d + k a c d = let (a',d') = f a d in (a', d' >>= \d'' -> c >>= \c' -> return (c' d'')) z a x = (a, return x) -- | gmapQl with accumulation -gmapAccumQl :: Data d - => (r -> r' -> r) +gmapAccumQl :: Data d + => (r -> r' -> r) -> r -> (forall d. Data d => a -> d -> (a,r')) -> a -> d -> (a, r) gmapAccumQl o r f a d = let (a',r) = gfoldlAccum k z a d in (a',unCONST r) where - k a (CONST c) d = let (a',r') = f a d + k a (CONST c) d = let (a',r') = f a d in (a', CONST (c `o` r')) z a _ = (a, CONST r) -- | gmapQr with accumulation -gmapAccumQr :: Data d - => (r' -> r -> r) +gmapAccumQr :: Data d + => (r' -> r -> r) -> r -> (forall d. Data d => a -> d -> (a,r')) -> a -> d -> (a, r) gmapAccumQr o r f a d = let (a',l) = gfoldlAccum k z a d in (a',unQr l r) where - k a (Qr c) d = let (a',r') = f a d + k a (Qr c) d = let (a',r') = f a d in (a', Qr (\r -> c (r' `o` r))) z a _ = (a, Qr id) @@ -151,7 +151,7 @@ gmapAccumQ f = gmapAccumQr (:) [] f ------------------------------------------------------------------------------ -- --- Helper type constructors +-- Helper type constructors -- ------------------------------------------------------------------------------ @@ -171,7 +171,7 @@ newtype Qr r a = Qr { unQr :: r -> r } ------------------------------------------------------------------------------ -- --- Mapping combinators for twin traversal +-- Mapping combinators for twin traversal -- ------------------------------------------------------------------------------ @@ -180,7 +180,7 @@ newtype Qr r a = Qr { unQr :: r -> r } gzipWithT :: GenericQ (GenericT) -> GenericQ (GenericT) gzipWithT f x y = case gmapAccumT perkid funs y of ([], c) -> c - _ -> error "gzipWithT" + _ -> error "gzipWithT" where perkid a d = (tail a, unGT (head a) d) funs = gmapQ (\k -> GT (f k)) x @@ -191,7 +191,7 @@ gzipWithT f x y = case gmapAccumT perkid funs y of gzipWithM :: Monad m => GenericQ (GenericM m) -> GenericQ (GenericM m) gzipWithM f x y = case gmapAccumM perkid funs y of ([], c) -> c - _ -> error "gzipWithM" + _ -> error "gzipWithM" where perkid a d = (tail a, unGM (head a) d) funs = gmapQ (\k -> GM (f k)) x @@ -201,7 +201,7 @@ gzipWithM f x y = case gmapAccumM perkid funs y of gzipWithQ :: GenericQ (GenericQ r) -> GenericQ (GenericQ [r]) gzipWithQ f x y = case gmapAccumQ perkid funs y of ([], r) -> r - _ -> error "gzipWithQ" + _ -> error "gzipWithQ" where perkid a d = (tail a, unGQ (head a) d) funs = gmapQ (\k -> GQ (f k)) x @@ -210,7 +210,7 @@ gzipWithQ f x y = case gmapAccumQ perkid funs y of ------------------------------------------------------------------------------ -- --- Typical twin traversals +-- Typical twin traversals -- ------------------------------------------------------------------------------ @@ -242,7 +242,7 @@ geq x y = geq' x y -- | Generic zip controlled by a function with type-specific branches gzip :: GenericQ (GenericM Maybe) -> GenericQ (GenericM Maybe) -- See testsuite/.../Generics/gzip.hs for an illustration -gzip f x y = +gzip f x y = f x y `orElse` if toConstr x == toConstr y -- 1.7.10.4