From 9c6b3f63b639e3febfc89327e6e698a0ed536d96 Mon Sep 17 00:00:00 2001 From: Ewout Date: Mon, 18 Jun 2018 21:24:19 +0200 Subject: [PATCH] Fix build on GHC 8.4 (#63) * Fix haddock: postfix comments on GADT constructors don't work. See https://github.com/haskell/haddock/issues/43 . * Remove unused dependencies from cabal file.. * Semigroup instances for compatibility with GHC 8.4. --- core/grpc-haskell-core.cabal | 9 +-------- core/src/Network/GRPC/Unsafe.chs | 3 ++- core/src/Network/GRPC/Unsafe/Metadata.chs | 8 ++++++-- grpc-haskell.cabal | 12 ------------ src/Network/GRPC/HighLevel/Client.hs | 6 +++--- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/core/grpc-haskell-core.cabal b/core/grpc-haskell-core.cabal index 7eaf5e3..959cb70 100644 --- a/core/grpc-haskell-core.cabal +++ b/core/grpc-haskell-core.cabal @@ -24,14 +24,7 @@ library , stm == 2.4.* , containers ==0.5.* , managed >= 1.0.0 && < 1.1 - , pipes >=4.1 && <=4.4 , transformers - , async ==2.1.* - , tasty >= 0.11 && <0.12 - , tasty-hunit >= 0.9 && <0.10 - , tasty-quickcheck >= 0.8.4 && < 0.9 - , safe ==0.3.* - , vector , sorted-list >=0.1.6.1 && <=0.3 c-sources: @@ -87,7 +80,7 @@ test-suite tests , bytestring ==0.10.* , unix , time - , async + , async ==2.1.* , tasty >= 0.11 && <0.12 , tasty-hunit >= 0.9 && <0.10 , tasty-quickcheck >= 0.8.4 && < 0.9 diff --git a/core/src/Network/GRPC/Unsafe.chs b/core/src/Network/GRPC/Unsafe.chs index 40280b2..3e3412b 100644 --- a/core/src/Network/GRPC/Unsafe.chs +++ b/core/src/Network/GRPC/Unsafe.chs @@ -7,6 +7,7 @@ import Control.Exception (bracket) import Control.Monad import Data.ByteString (ByteString, useAsCString) +import Data.Semigroup (Semigroup) import Foreign.C.String (CString, peekCString) import Foreign.Marshal.Alloc (free) @@ -30,7 +31,7 @@ import Network.GRPC.Unsafe.Constants {#context prefix = "grpc" #} newtype StatusDetails = StatusDetails {unStatusDetails :: ByteString} - deriving (Eq, IsString, Monoid, Show) + deriving (Eq, IsString, Monoid, Semigroup, Show) {#pointer *grpc_completion_queue as CompletionQueue newtype #} diff --git a/core/src/Network/GRPC/Unsafe/Metadata.chs b/core/src/Network/GRPC/Unsafe/Metadata.chs index 99276c3..9dd71a0 100644 --- a/core/src/Network/GRPC/Unsafe/Metadata.chs +++ b/core/src/Network/GRPC/Unsafe/Metadata.chs @@ -12,6 +12,7 @@ import Data.Function (on) import Data.ByteString (ByteString, useAsCString, useAsCStringLen) import Data.List (sortBy, groupBy) +import Data.Semigroup import qualified Data.SortedList as SL import qualified Data.Map.Strict as M import Data.Ord (comparing) @@ -35,10 +36,13 @@ newtype MetadataMap = MetadataMap {unMap :: M.Map ByteString (SL.SortedList Byte instance Show MetadataMap where show m = "fromList " ++ show (M.toList (unMap m)) +instance Semigroup MetadataMap where + (MetadataMap m1) <> (MetadataMap m2) = + MetadataMap $ M.unionWith mappend m1 m2 + instance Monoid MetadataMap where mempty = MetadataMap $ M.empty - mappend (MetadataMap m1) (MetadataMap m2) = - MetadataMap $ M.unionWith mappend m1 m2 + mappend = (<>) instance IsList MetadataMap where type Item MetadataMap = (ByteString, ByteString) diff --git a/grpc-haskell.cabal b/grpc-haskell.cabal index 7c34cd0..396d493 100644 --- a/grpc-haskell.cabal +++ b/grpc-haskell.cabal @@ -24,24 +24,12 @@ flag with-examples library build-depends: base >=4.8 && <5.0 - , clock >=0.6.0 && <0.8.0 , bytestring ==0.10.* - , stm == 2.4.* - , containers ==0.5.* - , managed >= 1.0.0 && < 1.1 - , pipes >=4.1 && <=4.4 - , transformers , proto3-suite , proto3-wire , grpc-haskell-core , async ==2.1.* - , tasty >= 0.11 && <0.12 - , tasty-hunit >= 0.9 && <0.10 - , tasty-quickcheck >= 0.8.4 && < 0.9 - , safe ==0.3.* - , vector - , sorted-list >=0.1.6.1 && <=0.3 exposed-modules: Network.GRPC.HighLevel diff --git a/src/Network/GRPC/HighLevel/Client.hs b/src/Network/GRPC/HighLevel/Client.hs index 408d1fa..812b755 100644 --- a/src/Network/GRPC/HighLevel/Client.hs +++ b/src/Network/GRPC/HighLevel/Client.hs @@ -54,10 +54,10 @@ data ClientError data ClientRequest (streamType :: GRPCMethodType) request response where ClientNormalRequest :: request -> TimeoutSeconds -> MetadataMap -> ClientRequest 'Normal request response ClientWriterRequest :: TimeoutSeconds -> MetadataMap -> (StreamSend request -> IO ()) -> ClientRequest 'ClientStreaming request response + -- | The final field will be invoked once, and it should repeatedly + -- invoke its final argument (of type @(StreamRecv response)@) + -- in order to obtain the streaming response incrementally. ClientReaderRequest :: request -> TimeoutSeconds -> MetadataMap -> (MetadataMap -> StreamRecv response -> IO ()) -> ClientRequest 'ServerStreaming request response - -- ^ The final field will be invoked once, and it should repeatedly - -- invoke its final argument (of type @(StreamRecv response)@) - -- in order to obtain the streaming response incrementally. ClientBiDiRequest :: TimeoutSeconds -> MetadataMap -> (MetadataMap -> StreamRecv response -> StreamSend request -> WritesDone -> IO ()) -> ClientRequest 'BiDiStreaming request response data ClientResult (streamType :: GRPCMethodType) response where