From: ralf Date: Sun, 15 Feb 2004 13:24:43 +0000 (+0000) Subject: [project @ 2004-02-15 13:24:42 by ralf] X-Git-Tag: nhc98-1-18-release~379 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=fe7274af44a32c8fb4d8100f531b5ccd8beb7d59;p=ghc-base.git [project @ 2004-02-15 13:24:42 by ralf] Another commit of boilerplate refactoring related to twin traversal and type introspection. Clean-up. After some reflection the list processing module was not regarded suitable for the library (see List.hs removed). --- diff --git a/Data/Generics.hs b/Data/Generics.hs index 58c5698..0732434 100644 --- a/Data/Generics.hs +++ b/Data/Generics.hs @@ -24,7 +24,6 @@ module Data.Generics ( module Data.Generics.Text, -- generic read and show module Data.Generics.Twins, -- twin traversal, e.g., generic eq module Data.Generics.Reify, -- experimental reification theme - module Data.Generics.List -- mapping over polymorphic lists #ifndef __HADDOCK__ , @@ -53,4 +52,3 @@ import Data.Generics.Schemes import Data.Generics.Text import Data.Generics.Twins import Data.Generics.Reify -import Data.Generics.List diff --git a/Data/Generics/List.hs b/Data/Generics/List.hs deleted file mode 100644 index 278a76f..0000000 --- a/Data/Generics/List.hs +++ /dev/null @@ -1,71 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Data.Generics.List --- 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 --- --- \"Scrap your boilerplate\" --- Generic programming in Haskell --- See . The present module illustrates --- one possible treatment of polymorphic datatypes for specialising --- generic functions. --- ------------------------------------------------------------------------------ - -module Data.Generics.List ( - - -- * Processing polymorphic lists - isList, - isNil, - isCons, - lgmapQ - - - ) where - - ------------------------------------------------------------------------------- - -#ifdef __HADDOCK__ -import Prelude -#endif -import Data.Maybe -import Data.Generics.Basics - -------------------------------------------------------------- --- --- Processing polymorphic lists --- -------------------------------------------------------------- - - --- | Test for list datatype -isList :: Data a => a -> Bool -isList x = typerepTyCon (typeOf x) == - typerepTyCon (typeOf (undefined::[()])) - - --- | Test for nil -isNil :: Data a => a -> Bool -isNil x = toConstr x == toConstr ([]::[()]) - - --- | Test for cons -isCons :: Data a => a -> Bool -isCons x = toConstr x == toConstr (():[]) - - --- | gmapQ for polymorphic lists; Nothing for other than lists -lgmapQ :: forall a q. Data a => (forall a. Data a => a -> q) -> a -> Maybe [q] -lgmapQ f x = - if not $ isList x - then Nothing - else Just ( if isNil x - then [] - else if isCons x - then ( gmapQi 0 f x : gmapQi 1 (fromJust . lgmapQ f) x ) - else error "lgmapQ" - ) diff --git a/Data/Generics/Twins.hs b/Data/Generics/Twins.hs index d432289..c12e8c9 100644 --- a/Data/Generics/Twins.hs +++ b/Data/Generics/Twins.hs @@ -245,9 +245,8 @@ couples of immediate subterms from the two given input terms.) geq x y = geq' x y where geq' :: forall a b. (Data a, Data b) => a -> b -> Bool - geq' x y = and ( (toConstr x == toConstr y) - : tmapQ geq' x y - ) + geq' x y = (toConstr x == toConstr y) + && and (tmapQ geq' x y) -- | Generic zip controlled by a function with type-specific branches