@@ -188,24 +188,38 @@ data SMethod (m :: Method f t) where
188
188
SCancelRequest :: SMethod CancelRequest
189
189
SCustomMethod :: Text -> SMethod CustomMethod
190
190
191
+ -- This instance is written manually rather than derived to avoid a dependency
192
+ -- on 'dependent-sum-template'.
191
193
instance GEq SMethod where
192
194
geq x y = case gcompare x y of
193
195
GLT -> Nothing
194
196
GEQ -> Just Refl
195
197
GGT -> Nothing
196
198
199
+ -- This instance is written manually rather than derived to avoid a dependency
200
+ -- on 'dependent-sum-template'.
197
201
instance GCompare SMethod where
198
202
gcompare (SCustomMethod x) (SCustomMethod y) = case x `compare` y of
199
203
LT -> GLT
200
204
EQ -> GEQ
201
205
GT -> GGT
206
+ -- This is much more compact than matching on every pair of constructors, which
207
+ -- is what we would need to do for GHC to 'see' that this is correct. Nonetheless
208
+ -- it is safe: since there is only one constructor of 'SMethod' for each 'Method',
209
+ -- the argument types can only be equal if the constructor tag is equal.
202
210
gcompare x y = case I # (dataToTag# x) `compare` I # (dataToTag# y) of
203
211
LT -> GLT
204
212
EQ -> unsafeCoerce GEQ
205
213
GT -> GGT
206
214
207
- deriving instance Eq (SMethod m )
208
- deriving instance Ord (SMethod m )
215
+ instance Eq (SMethod m ) where
216
+ -- This defers to 'GEq', ensuring that this version is compatible.
217
+ (==) = defaultEq
218
+
219
+ instance Ord (SMethod m ) where
220
+ -- This defers to 'GCompare', ensuring that this version is compatible.
221
+ compare = defaultCompare
222
+
209
223
deriving instance Show (SMethod m )
210
224
211
225
-- Some useful type synonyms
0 commit comments