@@ -78,24 +78,48 @@ deriving instance Show k => Show (Const2 k v v')
78deriving instance Read k => Read (Const2 k v v)
78deriving instance Read k => Read (Const2 k v v)
80instance Show k => GShow (Const2 k v) where
80instance Show k => GShow (Const2 k v) where
81+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
81 gshowToShow (Const2 _) = id
82 gshowToShow (Const2 _) = id
84+ gshowsPrec n x@(Const2 _) = showsPrec n x
83instance (Show k, Show (f v)) => ShowTag (Const2 k v) f where
87instance (Show k, Show (f v)) => ShowTag (Const2 k v) f where
88+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
84 showTagToShow (Const2 _) _ = id
89 showTagToShow (Const2 _) _ = id
91+ showTaggedPrec (Const2 _) = showsPrec
86instance Eq k => GEq (Const2 k v) where
94instance Eq k => GEq (Const2 k v) where
95+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
87 geqToEq _ = id
96 geqToEq _ = id
88 geqUnify (Const2 _) (Const2 _) _ = id
97 geqUnify (Const2 _) (Const2 _) _ = id
99+ geq (Const2 a) (Const2 b) =
90instance Ord k => GCompare (Const2 k v) where
105instance Ord k => GCompare (Const2 k v) where
106+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
91 gcompareToOrd (Const2 _) = id
107 gcompareToOrd (Const2 _) = id
92 gcompare (Const2 a) (Const2 b) = strengthenOrdering $ compare a b
108 gcompare (Const2 a) (Const2 b) = strengthenOrdering $ compare a b
110+ gcompare (Const2 a) (Const2 b) = case compare a b of
116+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
94instance {-# INCOHERENT #-} (Eq k, Eq v) => EqTag (Const2 k v) Identity where
117instance {-# INCOHERENT #-} (Eq k, Eq v) => EqTag (Const2 k v) Identity where
95 eqTagToEq (Const2 _) _ = id
118 eqTagToEq (Const2 _) _ = id
97instance {-# INCOHERENT #-} Eq k => EqTag (Const2 k v) (Const2 k v) where
120instance {-# INCOHERENT #-} Eq k => EqTag (Const2 k v) (Const2 k v) where
98 eqTagToEq (Const2 _) _ = id
121 eqTagToEq (Const2 _) _ = id
100-- | Convert a 'DMap' to a regular 'Map'
124-- | Convert a 'DMap' to a regular 'Map'
101dmapToMap :: DMap (Const2 k v) Identity -> Map k v
125dmapToMap :: DMap (Const2 k v) Identity -> Map k v
@@ -132,11 +156,17 @@ deriving instance Show (f a) => Show (WrapArg g f (g' a))
132deriving instance Read (f a) => Read (WrapArg g f (g a))
156deriving instance Read (f a) => Read (WrapArg g f (g a))
134instance GEq f => GEq (WrapArg g f) where
158instance GEq f => GEq (WrapArg g f) where
159+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
135 geqToEq (WrapArg f) = geqToEq f
160 geqToEq (WrapArg f) = geqToEq f
136 geqUnify (WrapArg a) (WrapArg b) = geqUnify a b
161 geqUnify (WrapArg a) (WrapArg b) = geqUnify a b
163+ geq (WrapArg a) (WrapArg b) = (\Refl -> Refl) <$> geq a b
138instance GCompare f => GCompare (WrapArg g f) where
166instance GCompare f => GCompare (WrapArg g f) where
167+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
139 gcompareToOrd (WrapArg f) = gcompareToOrd f
168 gcompareToOrd (WrapArg f) = gcompareToOrd f
140 gcompare (WrapArg a) (WrapArg b) = case gcompare a b of
170 gcompare (WrapArg a) (WrapArg b) = case gcompare a b of
141 GLT -> GLT
171 GLT -> GLT
142 GEQ -> GEQ
172 GEQ -> GEQ
@@ -188,6 +218,7 @@ deriving instance Show (EitherTag l r a)
188deriving instance Eq (EitherTag l r a)
218deriving instance Eq (EitherTag l r a)
189deriving instance Ord (EitherTag l r a)
219deriving instance Ord (EitherTag l r a)
221+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
191instance {-# INCOHERENT #-} (Show (f l), Show (f r)) => ShowTag (EitherTag l r) f where
222instance {-# INCOHERENT #-} (Show (f l), Show (f r)) => ShowTag (EitherTag l r) f where
192 showTagToShow e _ = case e of
223 showTagToShow e _ = case e of
193 LeftTag -> id
224 LeftTag -> id
@@ -197,32 +228,49 @@ instance {-# INCOHERENT #-} (Eq (f l), Eq (f r)) => EqTag (EitherTag l r) f wher
197 eqTagToEq e _ = case e of
228 eqTagToEq e _ = case e of
198 LeftTag -> id
229 LeftTag -> id
199 RightTag -> id
230 RightTag -> id
201instance GEq (EitherTag l r) where
233instance GEq (EitherTag l r) where
234+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
202 geqToEq _ = id
235 geqToEq _ = id
203 geqUnify LeftTag LeftTag _ same = same
236 geqUnify LeftTag LeftTag _ same = same
204 geqUnify RightTag RightTag _ same = same
237 geqUnify RightTag RightTag _ same = same
205 geqUnify _ _ unknown _ = unknown
238 geqUnify _ _ unknown _ = unknown
206 geq a b = case (a, b) of
240 geq a b = case (a, b) of
207 (LeftTag, LeftTag) -> Just Refl
241 (LeftTag, LeftTag) -> Just Refl
208 (RightTag, RightTag) -> Just Refl
242 (RightTag, RightTag) -> Just Refl
209 _ -> Nothing
243 _ -> Nothing
211instance GCompare (EitherTag l r) where
245instance GCompare (EitherTag l r) where
246+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
212 gcompareToOrd _ = id
247 gcompareToOrd _ = id
213 gcompare a b = case (a, b) of
249 gcompare a b = case (a, b) of
214 (LeftTag, LeftTag) -> GEQ
250 (LeftTag, LeftTag) -> GEQ
215 (LeftTag, RightTag) -> GLT
251 (LeftTag, RightTag) -> GLT
216 (RightTag, LeftTag) -> GGT
252 (RightTag, LeftTag) -> GGT
217 (RightTag, RightTag) -> GEQ
253 (RightTag, RightTag) -> GEQ
219−instance {-# INCOHERENT #-} GShow (EitherTag l r) where
255+instance GShow (EitherTag l r) where
256+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
220 gshowToShow _ = id
257 gshowToShow _ = id
259+ gshowsPrec _ a = case a of
260+ LeftTag -> showString "LeftTag"
261+ RightTag -> showString "RightTag"
222instance (Show l, Show r) => ShowTag (EitherTag l r) Identity where
264instance (Show l, Show r) => ShowTag (EitherTag l r) Identity where
265+#ifdef EXPERIMENTAL_DEPENDENT_SUM_INSTANCES
223 showTagToShow t _ = case t of
266 showTagToShow t _ = case t of
224 LeftTag -> id
267 LeftTag -> id
225 RightTag -> id
268 RightTag -> id
270+ showTaggedPrec t n (Identity a) = case t of
271+ LeftTag -> showsPrec n a
272+ RightTag -> showsPrec n a
227-- | Convert 'Either' to a 'DSum'. Inverse of 'dsumToEither'.
275-- | Convert 'Either' to a 'DSum'. Inverse of 'dsumToEither'.
228eitherToDSum :: Either a b -> DSum (EitherTag a b) Identity
276eitherToDSum :: Either a b -> DSum (EitherTag a b) Identity
@@ -245,14 +293,15 @@ dsumToEither = \case
245-- representational so that we can use safe 'coerce'.
293-- representational so that we can use safe 'coerce'.
246newtype ComposeMaybe f a = ComposeMaybe { getComposeMaybe :: Maybe (f a) } deriving (Show, Eq, Ord)
294newtype ComposeMaybe f a = ComposeMaybe { getComposeMaybe :: Maybe (f a) } deriving (Show, Eq, Ord)
248−instance EqTag f g => EqTag f (ComposeMaybe g) where
249− eqTagToEq f _ = eqTagToEq f (Proxy :: Proxy g)
251deriving instance Functor f => Functor (ComposeMaybe f)
296deriving instance Functor f => Functor (ComposeMaybe f)
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)
253instance {-# INCOHERENT #-} GShow k => ShowTag k (ComposeMaybe k) where
302instance {-# INCOHERENT #-} GShow k => ShowTag k (ComposeMaybe k) where
254 showTagToShow k _ r = gshowToShow k (showTagToShow k (Proxy :: Proxy k) r)
303 showTagToShow k _ r = gshowToShow k (showTagToShow k (Proxy :: Proxy k) r)
256--------------------------------------------------------------------------------
305--------------------------------------------------------------------------------
257-- Deprecated functions
306-- Deprecated functions
258--------------------------------------------------------------------------------
307--------------------------------------------------------------------------------