Skip to content

Commit

Permalink
Fix Ord instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
j6carey committed Sep 5, 2023
1 parent 3142924 commit 803edda
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Proto3/Suite/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ newtype Signed a = Signed { signed :: a }
-- | 'Enumerated' lifts any type with an 'IsEnum' instance so that it can be encoded
-- with 'HasEncoding'.
newtype Enumerated a = Enumerated { enumerated :: Either Int32 a }
deriving (Show, Ord, Generic, NFData, Functor, Foldable, Traversable)
deriving (Show, Generic, NFData, Functor, Foldable, Traversable)

-- | We consider two enumerated values to be equal if they serialize to the same code.
instance ProtoEnum a => Eq (Enumerated a) where
(==) = (==) `on` either id fromProtoEnum . enumerated
{-# INLINABLE (==) #-}

-- | We compare two enumerated values by comparing the code to which they serialize.
instance ProtoEnum a => Ord (Enumerated a) where
compare = compare `on` either id fromProtoEnum . enumerated
{-# INLINABLE (==) #-}

instance ProtoEnum a => Arbitrary (Enumerated a) where
arbitrary = do
i <- arbitrary
Expand Down

0 comments on commit 803edda

Please sign in to comment.