Abstract the set of types that gmapMFor takes out to a type.
(No change in behaviour, yet.)
This commit is contained in:
parent
441b2ee344
commit
0886ab9f9b
|
@ -24,6 +24,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-- added to in the definition of 'contains').
|
-- added to in the definition of 'contains').
|
||||||
module GenericUtils (
|
module GenericUtils (
|
||||||
TypeKey, typeKey
|
TypeKey, typeKey
|
||||||
|
, TypeSet, makeTypeSet
|
||||||
, containsTypes
|
, containsTypes
|
||||||
, gmapMFor
|
, gmapMFor
|
||||||
) where
|
) where
|
||||||
|
@ -101,11 +102,18 @@ containsTypes x targets
|
||||||
Just set -> target `IntSet.member` set
|
Just set -> target `IntSet.member` set
|
||||||
Nothing -> True -- can't tell, so it might be
|
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.
|
-- | Type-smart generic mapM.
|
||||||
-- This is like 'gmapM', but it only applies the function to arguments that
|
-- This is like 'gmapM', but it only applies the function to arguments that
|
||||||
-- could contain any of the target types.
|
-- could contain any of the target types.
|
||||||
gmapMFor :: (Monad m, Data t) =>
|
gmapMFor :: (Monad m, Data t) =>
|
||||||
[TypeKey] -- ^ Target types
|
TypeSet -- ^ Target types
|
||||||
-> (forall s. Data s => s -> m s) -- ^ Function to apply
|
-> (forall s. Data s => s -> m s) -- ^ Function to apply
|
||||||
-> (t -> m t) -- ^ Generic operation
|
-> (t -> m t) -- ^ Generic operation
|
||||||
gmapMFor targets f = gmapM (each f)
|
gmapMFor targets f = gmapM (each f)
|
||||||
|
|
|
@ -79,8 +79,11 @@ extC info f = extD info (checkToTransform f)
|
||||||
applyX :: Data s => InfoX -> s -> PassM s
|
applyX :: Data s => InfoX -> s -> PassM s
|
||||||
applyX info@(tks, g) = g doGeneric doGeneric
|
applyX info@(tks, g) = g doGeneric doGeneric
|
||||||
where
|
where
|
||||||
|
ts :: TypeSet
|
||||||
|
ts = makeTypeSet tks
|
||||||
|
|
||||||
doGeneric :: Data t => t -> PassM t
|
doGeneric :: Data t => t -> PassM t
|
||||||
doGeneric = gmapMFor tks (applyX info)
|
doGeneric = gmapMFor ts (applyX info)
|
||||||
|
|
||||||
-- | Apply a transformation, recursing depth-first.
|
-- | Apply a transformation, recursing depth-first.
|
||||||
applyDepthM :: forall t1 s. (Data t1, Data s) =>
|
applyDepthM :: forall t1 s. (Data t1, Data s) =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user