Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Data/GADT/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Data.Maybe (isJust, isNothing)
import Data.Monoid (Monoid (..))
import Data.Semigroup (Semigroup (..))
import Data.Type.Equality ((:~:) (..))
import GHC.Generics ((:+:) (..))

#if __GLASGOW_HASKELL__ >=708
import Data.Typeable (Typeable)
Expand Down Expand Up @@ -181,6 +182,15 @@ instance (GEq a, GEq b) => GEq (Product a b) where
Refl <- geq y y'
return Refl

instance (GEq f, GEq g) => GEq (f :+: g) where
geq x y = case x of
L1 f -> case y of
L1 f' -> geq f f'
R1 _ -> Nothing
R1 g -> case y of
L1 _ -> Nothing
R1 g' -> geq g g'

#if MIN_VERSION_base(4,10,0)
instance GEq TR.TypeRep where
geq = testEquality
Expand Down Expand Up @@ -297,6 +307,15 @@ instance (GCompare a, GCompare b) => GCompare (Product a b) where
GEQ -> GEQ
GGT -> GGT

instance (GCompare f, GCompare g) => GCompare (f :+: g) where
gcompare x y = case x of
L1 f -> case y of
L1 f' -> gcompare f f'
R1 _ -> GLT
R1 g -> case y of
L1 _ -> GLT
R1 g' -> gcompare g g'

-------------------------------------------------------------------------------
-- Some
-------------------------------------------------------------------------------
Expand Down