From 94dc10bc5f7cbf36814e9158979d0e8fde7c5eef Mon Sep 17 00:00:00 2001 From: simonpj Date: Fri, 6 Jan 2006 15:51:23 +0000 Subject: [PATCH] [project @ 2006-01-06 15:51:23 by simonpj] Eta-expand some higher-rank functions. GHC is about to move to *invariant* rather than *contra-variant* in function arguments, so far as type subsumption is concerned. These eta-expansions are simple, and allow type inference to go through with invariance. --- Data/Generics/Instances.hs | 10 +++++----- Data/Generics/Twins.hs | 6 ++---- Data/IntMap.hs | 2 +- Data/Map.hs | 2 +- Data/Sequence.hs | 2 +- Data/Set.hs | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Data/Generics/Instances.hs b/Data/Generics/Instances.hs index 926c161..75de715 100644 --- a/Data/Generics/Instances.hs +++ b/Data/Generics/Instances.hs @@ -279,7 +279,7 @@ instance Data a => Data [a] where 2 -> k (k (z (:))) _ -> error "gunfold" dataTypeOf _ = listDataType - dataCast1 = gcast1 + dataCast1 f = gcast1 f -- -- The gmaps are given as an illustration. @@ -310,7 +310,7 @@ instance Data a => Data (Maybe a) where 2 -> k (z Just) _ -> error "gunfold" dataTypeOf _ = maybeDataType - dataCast1 = gcast1 + dataCast1 f = gcast1 f ------------------------------------------------------------------------------ @@ -353,7 +353,7 @@ instance (Data a, Data b) => Data (Either a b) where 2 -> k (z Right) _ -> error "gunfold" dataTypeOf _ = eitherDataType - dataCast2 = gcast2 + dataCast2 f = gcast2 f ------------------------------------------------------------------------------ @@ -367,7 +367,7 @@ instance (Data a, Data b) => Data (a -> b) where toConstr _ = error "toConstr" gunfold _ _ = error "gunfold" dataTypeOf _ = mkNorepType "Prelude.(->)" - dataCast2 = gcast2 + dataCast2 f = gcast2 f ------------------------------------------------------------------------------ @@ -395,7 +395,7 @@ instance (Data a, Data b) => Data (a,b) where gunfold k z c | constrIndex c == 1 = k (k (z (,))) gunfold _ _ _ = error "gunfold" dataTypeOf _ = tuple2DataType - dataCast2 = gcast2 + dataCast2 f = gcast2 f ------------------------------------------------------------------------------ diff --git a/Data/Generics/Twins.hs b/Data/Generics/Twins.hs index dcc01aa..eed4ab6 100644 --- a/Data/Generics/Twins.hs +++ b/Data/Generics/Twins.hs @@ -234,15 +234,13 @@ 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' :: GenericQ (GenericQ Bool) geq' x y = (toConstr x == toConstr y) && and (gzipWithQ geq' x y) -- | Generic zip controlled by a function with type-specific branches -gzip :: (forall a b. (Data a, Data b) => a -> b -> Maybe b) - -> (forall a b. (Data a, Data b) => a -> b -> Maybe b) - +gzip :: GenericQ (GenericM Maybe) -> GenericQ (GenericM Maybe) -- See testsuite/.../Generics/gzip.hs for an illustration gzip f x y = f x y diff --git a/Data/IntMap.hs b/Data/IntMap.hs index d5fc9e7..1606413 100644 --- a/Data/IntMap.hs +++ b/Data/IntMap.hs @@ -236,7 +236,7 @@ instance Data a => Data (IntMap a) where toConstr _ = error "toConstr" gunfold _ _ = error "gunfold" dataTypeOf _ = mkNorepType "Data.IntMap.IntMap" - dataCast1 = gcast1 + dataCast1 f = gcast1 f #endif diff --git a/Data/Map.hs b/Data/Map.hs index beddb7b..d88ceb5 100644 --- a/Data/Map.hs +++ b/Data/Map.hs @@ -216,7 +216,7 @@ instance (Data k, Data a, Ord k) => Data (Map k a) where toConstr _ = error "toConstr" gunfold _ _ = error "gunfold" dataTypeOf _ = mkNorepType "Data.Map.Map" - dataCast2 = gcast2 + dataCast2 f = gcast2 f #endif diff --git a/Data/Sequence.hs b/Data/Sequence.hs index d072a28..3d38011 100644 --- a/Data/Sequence.hs +++ b/Data/Sequence.hs @@ -178,7 +178,7 @@ instance Data a => Data (Seq a) where dataTypeOf _ = seqDataType - dataCast1 = gcast1 + dataCast1 f = gcast1 f emptyConstr = mkConstr seqDataType "empty" [] Prefix consConstr = mkConstr seqDataType "<|" [] Infix diff --git a/Data/Set.hs b/Data/Set.hs index f0994e5..13dff75 100644 --- a/Data/Set.hs +++ b/Data/Set.hs @@ -171,7 +171,7 @@ instance (Data a, Ord a) => Data (Set a) where toConstr _ = error "toConstr" gunfold _ _ = error "gunfold" dataTypeOf _ = mkNorepType "Data.Set.Set" - dataCast1 = gcast1 + dataCast1 f = gcast1 f #endif -- 1.7.10.4