@@ -78,24 +78,48 @@ deriving instance Show k => Show (Const2 k v v')
7878deriving instance Read k => Read (Const2 k v v)
7979
8080instance Show k => GShow (Const2 k v) where
81+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
8182 gshowToShow (Const2 _) = id
83+#else
84+ gshowsPrec n x@(Const2 _) = showsPrec n x
85+#endif
8286
8387instance (Show k, Show (f v)) => ShowTag (Const2 k v) f where
88+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
8489 showTagToShow (Const2 _) _ = id
90+#else
91+ showTaggedPrec (Const2 _) = showsPrec
92+#endif
8593
8694instance Eq k => GEq (Const2 k v) where
95+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
8796 geqToEq _ = id
8897 geqUnify (Const2 _) (Const2 _) _ = id
98+#else
99+ geq (Const2 a) (Const2 b) =
100+ if a == b
101+ then Just Refl
102+ else Nothing
103+#endif
89104
90105instance Ord k => GCompare (Const2 k v) where
106+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
91107 gcompareToOrd (Const2 _) = id
92108 gcompare (Const2 a) (Const2 b) = strengthenOrdering $ compare a b
109+#else
110+ gcompare (Const2 a) (Const2 b) = case compare a b of
111+ LT -> GLT
112+ EQ -> GEQ
113+ GT -> GGT
114+#endif
93115
116+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
94117instance {-# INCOHERENT #-} (Eq k, Eq v) => EqTag (Const2 k v) Identity where
95118 eqTagToEq (Const2 _) _ = id
96119
97120instance {-# INCOHERENT #-} Eq k => EqTag (Const2 k v) (Const2 k v) where
98121 eqTagToEq (Const2 _) _ = id
122+#endif
99123
100124-- | Convert a 'DMap' to a regular 'Map'
101125dmapToMap :: DMap (Const2 k v) Identity -> Map k v
@@ -132,11 +156,17 @@ deriving instance Show (f a) => Show (WrapArg g f (g' a))
132156deriving instance Read (f a) => Read (WrapArg g f (g a))
133157
134158instance GEq f => GEq (WrapArg g f) where
159+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
135160 geqToEq (WrapArg f) = geqToEq f
136161 geqUnify (WrapArg a) (WrapArg b) = geqUnify a b
162+#else
163+ geq (WrapArg a) (WrapArg b) = (\Refl -> Refl) <$> geq a b
164+#endif
137165
138166instance GCompare f => GCompare (WrapArg g f) where
167+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
139168 gcompareToOrd (WrapArg f) = gcompareToOrd f
169+#endif
140170 gcompare (WrapArg a) (WrapArg b) = case gcompare a b of
141171 GLT -> GLT
142172 GEQ -> GEQ
@@ -188,6 +218,7 @@ deriving instance Show (EitherTag l r a)
188218deriving instance Eq (EitherTag l r a)
189219deriving instance Ord (EitherTag l r a)
190220
221+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
191222instance {-# INCOHERENT #-} (Show (f l), Show (f r)) => ShowTag (EitherTag l r) f where
192223 showTagToShow e _ = case e of
193224 LeftTag -> id
@@ -197,32 +228,49 @@ instance {-# INCOHERENT #-} (Eq (f l), Eq (f r)) => EqTag (EitherTag l r) f wher
197228 eqTagToEq e _ = case e of
198229 LeftTag -> id
199230 RightTag -> id
231+#endif
200232
201233instance GEq (EitherTag l r) where
234+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
202235 geqToEq _ = id
203236 geqUnify LeftTag LeftTag _ same = same
204237 geqUnify RightTag RightTag _ same = same
205238 geqUnify _ _ unknown _ = unknown
239+#endif
206240 geq a b = case (a, b) of
207241 (LeftTag, LeftTag) -> Just Refl
208242 (RightTag, RightTag) -> Just Refl
209243 _ -> Nothing
210244
211245instance GCompare (EitherTag l r) where
246+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
212247 gcompareToOrd _ = id
248+#endif
213249 gcompare a b = case (a, b) of
214250 (LeftTag, LeftTag) -> GEQ
215251 (LeftTag, RightTag) -> GLT
216252 (RightTag, LeftTag) -> GGT
217253 (RightTag, RightTag) -> GEQ
218254
219−instance {-# INCOHERENT #-} GShow (EitherTag l r) where
255+instance GShow (EitherTag l r) where
256+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
220257 gshowToShow _ = id
258+#else
259+ gshowsPrec _ a = case a of
260+ LeftTag -> showString "LeftTag"
261+ RightTag -> showString "RightTag"
262+#endif
221263
222264instance (Show l, Show r) => ShowTag (EitherTag l r) Identity where
265+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
223266 showTagToShow t _ = case t of
224267 LeftTag -> id
225268 RightTag -> id
269+#else
270+ showTaggedPrec t n (Identity a) = case t of
271+ LeftTag -> showsPrec n a
272+ RightTag -> showsPrec n a
273+#endif
226274
227275-- | Convert 'Either' to a 'DSum'. Inverse of 'dsumToEither'.
228276eitherToDSum :: Either a b -> DSum (EitherTag a b) Identity
@@ -245,14 +293,15 @@ dsumToEither = \case
245293-- representational so that we can use safe 'coerce'.
246294newtype ComposeMaybe f a = ComposeMaybe { getComposeMaybe :: Maybe (f a) } deriving (Show, Eq, Ord)
247295
248−instance EqTag f g => EqTag f (ComposeMaybe g) where
249− eqTagToEq f _ = eqTagToEq f (Proxy :: Proxy g)
250−
251296deriving instance Functor f => Functor (ComposeMaybe f)
252297
298+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
299+instance {-# INCOHERENT #-} EqTag f g => EqTag f (ComposeMaybe g) where
300+ eqTagToEq f _ = eqTagToEq f (Proxy :: Proxy g)
301+
253302instance {-# INCOHERENT #-} GShow k => ShowTag k (ComposeMaybe k) where
254303 showTagToShow k _ r = gshowToShow k (showTagToShow k (Proxy :: Proxy k) r)
255−
304+#endif
256305--------------------------------------------------------------------------------
257306-- Deprecated functions
258307--------------------------------------------------------------------------------