Skip to content

Commit

Permalink
Change Show implementation for FieldNumber (awakesecurity#13)
Browse files Browse the repository at this point in the history
The derived `Show` instance for `FieldNumber` is more verbose than
necessary.  This change takes advantage of the fact that `FieldNumber`
implements `Num` so that the `Show` implementation can display just a
numeric literal.  This is still valid code for building a `FieldNumber`.
  • Loading branch information
Gabriella439 authored May 7, 2017
1 parent e931056 commit d78e2a3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Proto3/Wire/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import Test.QuickCheck ( Arbitrary(..), choose )
-- sure that field numbers are provided in increasing order. Such things are
-- left to other, higher-level libraries.
newtype FieldNumber = FieldNumber { getFieldNumber :: Word64 }
deriving (Show, Eq, Ord, Enum, Hashable, NFData, Num)
deriving (Eq, Ord, Enum, Hashable, NFData, Num)

instance Show FieldNumber where
show (FieldNumber n) = show n

instance Arbitrary FieldNumber where
arbitrary = fmap FieldNumber $ choose (1, 536870911)
Expand Down

0 comments on commit d78e2a3

Please sign in to comment.