From 0886ab9f9b23baf04f90f94f44aeec113a5660f2 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Tue, 8 Apr 2008 23:13:58 +0000 Subject: [PATCH] Abstract the set of types that gmapMFor takes out to a type. (No change in behaviour, yet.) --- common/GenericUtils.hs | 10 +++++++++- pass/Traversal.hs | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/common/GenericUtils.hs b/common/GenericUtils.hs index 7547517..78fe23d 100644 --- a/common/GenericUtils.hs +++ b/common/GenericUtils.hs @@ -24,6 +24,7 @@ with this program. If not, see . -- added to in the definition of 'contains'). module GenericUtils ( TypeKey, typeKey + , TypeSet, makeTypeSet , containsTypes , gmapMFor ) where @@ -101,11 +102,18 @@ containsTypes x targets Just set -> target `IntSet.member` set Nothing -> True -- can't tell, so it might be +-- | A set of type information for use by 'gmapMFor'. +type TypeSet = [TypeKey] + +-- | Make a 'TypeSet' from a list of 'TypeKey's. +makeTypeSet :: [TypeKey] -> TypeSet +makeTypeSet tks = tks + -- | Type-smart generic mapM. -- This is like 'gmapM', but it only applies the function to arguments that -- could contain any of the target types. gmapMFor :: (Monad m, Data t) => - [TypeKey] -- ^ Target types + TypeSet -- ^ Target types -> (forall s. Data s => s -> m s) -- ^ Function to apply -> (t -> m t) -- ^ Generic operation gmapMFor targets f = gmapM (each f) diff --git a/pass/Traversal.hs b/pass/Traversal.hs index 00e3c16..587c15d 100644 --- a/pass/Traversal.hs +++ b/pass/Traversal.hs @@ -79,8 +79,11 @@ extC info f = extD info (checkToTransform f) applyX :: Data s => InfoX -> s -> PassM s applyX info@(tks, g) = g doGeneric doGeneric where + ts :: TypeSet + ts = makeTypeSet tks + doGeneric :: Data t => t -> PassM t - doGeneric = gmapMFor tks (applyX info) + doGeneric = gmapMFor ts (applyX info) -- | Apply a transformation, recursing depth-first. applyDepthM :: forall t1 s. (Data t1, Data s) =>