Skip to content

Commit

Permalink
Suport discrimination 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tochicool authored and blackgnezdo committed Jun 18, 2022
1 parent 6ca9b46 commit 058ee44
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions discrimination-ieee754/discrimination-ieee754.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ library
base >=4.10 && <4.17
, contravariant >=1.3 && <1.6
, data-binary-ieee754 ==0.4.*
, discrimination >=0.3 && <0.5
, discrimination >=0.3 && <0.6
default-language: Haskell2010

test-suite test
Expand All @@ -49,7 +49,7 @@ test-suite test
, base >=4.10 && <4.17
, contravariant >=1.3 && <1.6
, data-binary-ieee754 ==0.4.*
, discrimination >=0.3 && <0.5
, discrimination >=0.3 && <0.6
, discrimination-ieee754
, test-framework
, test-framework-quickcheck2 ==0.3.*
Expand Down
2 changes: 1 addition & 1 deletion discrimination-ieee754/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- base >= 4.10 && < 4.17
- data-binary-ieee754 >= 0.4 && < 0.5
- contravariant >= 1.3 && < 1.6
- discrimination >= 0.3 && < 0.5
- discrimination >= 0.3 && < 0.6

library:
source-dirs: src
Expand Down
2 changes: 1 addition & 1 deletion proto-lens-discrimination/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- bytestring >= 0.10 && < 0.12
- contravariant >= 1.3 && < 1.6
- containers >= 0.5 && < 0.7
- discrimination >= 0.3 && < 0.5
- discrimination >= 0.3 && < 0.6
- discrimination-ieee754 == 0.1.*
- lens-family >= 1.2 && < 2.2
- proto-lens >= 0.6 && < 0.8
Expand Down
4 changes: 2 additions & 2 deletions proto-lens-discrimination/proto-lens-discrimination.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ library
, bytestring >=0.10 && <0.12
, containers >=0.5 && <0.7
, contravariant >=1.3 && <1.6
, discrimination >=0.3 && <0.5
, discrimination >=0.3 && <0.6
, discrimination-ieee754 ==0.1.*
, lens-family >=1.2 && <2.2
, proto-lens >=0.6 && <0.8
Expand Down Expand Up @@ -80,7 +80,7 @@ test-suite discrimination_test
, bytestring >=0.10 && <0.12
, containers >=0.5 && <0.7
, contravariant >=1.3 && <1.6
, discrimination >=0.3 && <0.5
, discrimination >=0.3 && <0.6
, discrimination-ieee754 ==0.1.*
, lens-family >=1.2 && <2.2
, proto-lens >=0.6 && <0.8
Expand Down
5 changes: 3 additions & 2 deletions proto-lens-discrimination/src/Data/ProtoLens/Group.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ import Data.ProtoLens.Discrimination
-- Used internally to adapt 'groupingEq' to protobuf types without adding an
-- orphan instance for Grouping.
newtype MessageGrouping a = MessageGrouping { getMessageGrouping :: a }
instance Message a => Grouping (MessageGrouping a) where
deriving Eq
instance (Message a, Eq a) => Grouping (MessageGrouping a) where
grouping = getMessageGrouping >$< groupingMessage

-- | Check whether two protobufs are equal according to their Message instance.
--
-- This should be equivalent to the generated @Eq@ instances.
eqMessage :: Message a => a -> a -> Bool
eqMessage :: (Message a, Eq a) => a -> a -> Bool
eqMessage x y = groupingEq (MessageGrouping x) (MessageGrouping y)

-- | Group protobuf message values according to their Message instance.
Expand Down
7 changes: 4 additions & 3 deletions proto-lens-discrimination/src/Data/ProtoLens/Sort.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ import Data.ProtoLens.Group (groupingMessage)
-- Used to adapt 'sortingCompare' to protobuf types without adding an orphan
-- instance for Sorting.
newtype MessageSorting a = MessageSorting { getMessageSorting :: a }
instance Message a => Grouping (MessageSorting a) where
deriving (Eq, Ord)
instance (Message a, Eq a) => Grouping (MessageSorting a) where
grouping = getMessageSorting >$< groupingMessage
instance Message a => Sorting (MessageSorting a) where
instance (Message a, Ord a) => Sorting (MessageSorting a) where
sorting = getMessageSorting >$< sortingMessage

-- | Compare protobuf message values according to their Message instance.
compareMessage :: Message a => a -> a -> Ordering
compareMessage :: (Message a, Ord a) => a -> a -> Ordering
compareMessage x y = sortingCompare (MessageSorting x) (MessageSorting y)

-- | Sort protobuf message values according to their Message instance.
Expand Down
2 changes: 1 addition & 1 deletion stack-9.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

resolver: nightly-2022-04-04
resolver: nightly-2022-06-18
compiler: ghc-9.2.2

packages:
Expand Down

0 comments on commit 058ee44

Please sign in to comment.