@@ -27,6 +27,8 @@ import Data.Maybe (isJust, isNothing)
2727import Data.Monoid (Monoid (.. ))
2828import Data.Semigroup (Semigroup (.. ))
2929import Data.Type.Equality ((:~:) (.. ))
30+ import GHC.Generics ((:+:) (.. ))
31+ import GHC.Generics ((:*:) (.. ))
3032
3133#if __GLASGOW_HASKELL__ >=708
3234import Data.Typeable (Typeable )
@@ -199,6 +201,17 @@ instance (GEq a, GEq b) => GEq (Product a b) where
199201 Refl <- geq y y'
200202 return Refl
201203
204+ instance (GEq f , GEq g ) => GEq (f :+: g ) where
205+ geq (L1 x) (L1 y) = geq x y
206+ geq (R1 x) (R1 y) = geq x y
207+ geq _ _ = Nothing
208+
209+ instance (GEq a , GEq b ) => GEq (a :*: b ) where
210+ geq (x :*: y) (x' :*: y') = do
211+ Refl <- geq x x'
212+ Refl <- geq y y'
213+ return Refl
214+
202215#if MIN_VERSION_base(4,10,0)
203216instance GEq TR. TypeRep where
204217 geq = testEquality
@@ -321,6 +334,21 @@ instance (GCompare a, GCompare b) => GCompare (Product a b) where
321334 GEQ -> GEQ
322335 GGT -> GGT
323336
337+ instance (GCompare f , GCompare g ) => GCompare (f :+: g ) where
338+ gcompare (L1 x) (L1 y) = gcompare x y
339+ gcompare (L1 _) (R1 _) = GLT
340+ gcompare (R1 _) (L1 _) = GGT
341+ gcompare (R1 x) (R1 y) = gcompare x y
342+
343+ instance (GCompare a , GCompare b ) => GCompare (a :*: b ) where
344+ gcompare (x :*: y) (x' :*: y') = case gcompare x x' of
345+ GLT -> GLT
346+ GGT -> GGT
347+ GEQ -> case gcompare y y' of
348+ GLT -> GLT
349+ GEQ -> GEQ
350+ GGT -> GGT
351+
324352-------------------------------------------------------------------------------
325353-- Some
326354-------------------------------------------------------------------------------
0 commit comments