From 7133e9dad21bead6b2cc76ccec2e7ba3ab0c33e8 Mon Sep 17 00:00:00 2001 From: Nathan van Doorn Date: Wed, 5 Sep 2018 13:15:42 +0100 Subject: [PATCH 1/2] Add bifunctors instances for Servant.API.Alt These mirror the corresponding instances for (,) --- servant/servant.cabal | 1 + servant/src/Servant/API/Alternative.hs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/servant/servant.cabal b/servant/servant.cabal index bfbec007..89bb13a3 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -84,6 +84,7 @@ library -- Here can be exceptions if we really need features from the newer versions. build-depends: base-compat >= 0.10.4 && < 0.11 + , bifunctors >= 5.4 && < 5.6 , aeson >= 1.3.1.1 && < 1.5 , attoparsec >= 0.13.2.2 && < 0.14 , case-insensitive >= 1.2.0.11 && < 1.3 diff --git a/servant/src/Servant/API/Alternative.hs b/servant/src/Servant/API/Alternative.hs index 5f8e393c..60152ac1 100644 --- a/servant/src/Servant/API/Alternative.hs +++ b/servant/src/Servant/API/Alternative.hs @@ -7,6 +7,15 @@ {-# OPTIONS_HADDOCK not-home #-} module Servant.API.Alternative ((:<|>)(..)) where +import Control.Applicative (liftA2) +import Data.Biapplicative + (Biapplicative (..)) +import Data.Bifoldable + (Bifoldable (..)) +import Data.Bifunctor + (Bifunctor (..)) +import Data.Bitraversable + (Bitraversable (..)) import Data.Semigroup (Semigroup (..)) import Data.Typeable @@ -33,6 +42,19 @@ instance (Monoid a, Monoid b) => Monoid (a :<|> b) where mempty = mempty :<|> mempty (a :<|> b) `mappend` (a' :<|> b') = (a `mappend` a') :<|> (b `mappend` b') +instance Bifoldable (:<|>) where + bifoldMap f g ~(a :<|> b) = f a `mappend` g b + +instance Bifunctor (:<|>) where + bimap f g ~(a :<|> b) = f a :<|> g b + +instance Biapplicative (:<|>) where + bipure = (:<|>) + (f :<|> g) <<*>> (a :<|> b) = f a :<|> g b + +instance Bitraversable (:<|>) where + bitraverse f g ~(a :<|> b) = liftA2 (:<|>) (f a) (g b) + -- $setup -- >>> import Servant.API -- >>> import Data.Aeson From 43a1d586fe4963d2397006beace4906e1fb0e2c7 Mon Sep 17 00:00:00 2001 From: Nathan van Doorn Date: Fri, 7 Sep 2018 09:58:09 +0100 Subject: [PATCH 2/2] Raise lower bound on bifunctors to match Stackage LTS --- servant/servant.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servant/servant.cabal b/servant/servant.cabal index 89bb13a3..f7f76d27 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -84,7 +84,7 @@ library -- Here can be exceptions if we really need features from the newer versions. build-depends: base-compat >= 0.10.4 && < 0.11 - , bifunctors >= 5.4 && < 5.6 + , bifunctors >= 5.5.3 && < 5.6 , aeson >= 1.3.1.1 && < 1.5 , attoparsec >= 0.13.2.2 && < 0.14 , case-insensitive >= 1.2.0.11 && < 1.3