From 276dfd8b43e69692c0bf5e2307ec6b8ffacdaa2a Mon Sep 17 00:00:00 2001 From: Nickolay Kudasov Date: Wed, 20 Jan 2016 03:35:48 +0300 Subject: [PATCH] Fix GHC 7.8 build --- servant-cassava/servant-cassava.cabal | 3 ++- servant-cassava/src/Servant/CSV/Cassava.hs | 10 ++++----- servant-server/src/Servant/Server/Internal.hs | 1 + servant/servant.cabal | 6 +++-- servant/src/Servant/API/ContentTypes.hs | 22 +++++++++---------- servant/test/Servant/API/ContentTypesSpec.hs | 6 ++--- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/servant-cassava/servant-cassava.cabal b/servant-cassava/servant-cassava.cabal index f1643e06e..df19b4f98 100644 --- a/servant-cassava/servant-cassava.cabal +++ b/servant-cassava/servant-cassava.cabal @@ -23,7 +23,8 @@ library build-depends: base >=4.6 && <5 , cassava >0.4 && <0.5 , servant ==0.5.* - , mtl >= 2 && < 3 + , transformers + , transformers-compat , http-media , vector hs-source-dirs: src diff --git a/servant-cassava/src/Servant/CSV/Cassava.hs b/servant-cassava/src/Servant/CSV/Cassava.hs index e1da5c52b..f91b42302 100644 --- a/servant-cassava/src/Servant/CSV/Cassava.hs +++ b/servant-cassava/src/Servant/CSV/Cassava.hs @@ -20,7 +20,7 @@ module Servant.CSV.Cassava where #if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<$>)) #endif -import Control.Monad.Except (ExceptT, MonadError(..)) +import Control.Monad.Trans.Except (ExceptT, throwE) import Data.Csv import Data.Proxy (Proxy (..)) import Data.Typeable (Typeable) @@ -85,26 +85,26 @@ instance EncodeOpts DefaultEncodeOpts where -- | Decode with 'decodeByNameWith' instance ( FromNamedRecord a, DecodeOpts opt ) => MimeUnrender (CSV', opt) (Header, [a]) where - mimeUnrender _ bs = either throwError return $ + mimeUnrender _ bs = either throwE return $ fmap toList <$> decodeByNameWith (decodeOpts p) bs where p = Proxy :: Proxy opt -- | Decode with 'decodeWith'. Assumes data has headers, which are stripped. instance ( FromRecord a, DecodeOpts opt ) => MimeUnrender (CSV', opt) [a] where - mimeUnrender _ bs = either throwError return $ + mimeUnrender _ bs = either throwE return $ toList <$> decodeWith (decodeOpts p) HasHeader bs where p = Proxy :: Proxy opt instance ( FromNamedRecord a, DecodeOpts opt ) => MimeUnrender (CSV', opt) (Header, Vector a) where - mimeUnrender _ = either throwError return . decodeByNameWith (decodeOpts p) + mimeUnrender _ = either throwE return . decodeByNameWith (decodeOpts p) where p = Proxy :: Proxy opt -- | Decode with 'decodeWith'. Assumes data has headers, which are stripped. instance ( FromRecord a, DecodeOpts opt ) => MimeUnrender (CSV', opt) (Vector a) where - mimeUnrender _ = either throwError return . decodeWith (decodeOpts p) HasHeader + mimeUnrender _ = either throwE return . decodeWith (decodeOpts p) HasHeader where p = Proxy :: Proxy opt -- ** Decode Options diff --git a/servant-server/src/Servant/Server/Internal.hs b/servant-server/src/Servant/Server/Internal.hs index 4802ccc2e..7b27bf7c4 100644 --- a/servant-server/src/Servant/Server/Internal.hs +++ b/servant-server/src/Servant/Server/Internal.hs @@ -20,6 +20,7 @@ module Servant.Server.Internal #if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<$>)) +import Data.Traversable (traverse) #endif import Control.Monad.Trans.Except (ExceptT, runExceptT) import Control.Monad.Trans (liftIO) diff --git a/servant/servant.cabal b/servant/servant.cabal index e716f2867..d40c1acbd 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -52,8 +52,9 @@ library , http-api-data >= 0.1 && < 0.3 , http-media >= 0.4 && < 0.7 , http-types >= 0.8 && < 0.10 - , mtl >= 2 && < 3 , text >= 1 && < 2 + , transformers + , transformers-compat , string-conversions >= 0.3 && < 0.5 , network-uri >= 2.6 , vault >= 0.3 && <0.4 @@ -99,12 +100,13 @@ test-suite spec , attoparsec , bytestring , hspec == 2.* - , mtl >= 2 && < 3 , QuickCheck , quickcheck-instances , servant , string-conversions , text + , transformers + , transformers-compat , url test-suite doctests diff --git a/servant/src/Servant/API/ContentTypes.hs b/servant/src/Servant/API/ContentTypes.hs index 188bbdd43..c6d38d1c5 100644 --- a/servant/src/Servant/API/ContentTypes.hs +++ b/servant/src/Servant/API/ContentTypes.hs @@ -77,7 +77,7 @@ import Control.Applicative ((*>), (<*)) #endif import Control.Arrow (left) import Control.Monad -import Control.Monad.Except (ExceptT, MonadError(..)) +import Control.Monad.Trans.Except (ExceptT, throwE) import Data.Aeson (FromJSON(..), ToJSON(..), encode) import Data.Aeson.Parser (value) import Data.Aeson.Types (parseEither) @@ -185,7 +185,7 @@ instance OVERLAPPABLE_ -- -- >>> import Network.HTTP.Media hiding (Accept) -- >>> import qualified Data.ByteString.Lazy.Char8 as BSC --- >>> import Control.Monad.Except +-- >>> import Control.Monad.Trans.Except -- >>> data MyContentType = MyContentType String -- -- >>> :{ @@ -197,7 +197,7 @@ instance OVERLAPPABLE_ --instance Read a => MimeUnrender MyContentType a where -- mimeUnrender _ bs = case BSC.take 12 bs of -- "MyContentType" -> return . read . BSC.unpack $ BSC.drop 12 bs --- _ -> throwError "didn't start with the magic incantation" +-- _ -> throwE "didn't start with the magic incantation" -- :} -- -- >>> type MyAPI = "path" :> ReqBody '[MyContentType] Int :> Get '[JSON] Int @@ -347,23 +347,23 @@ eitherDecodeLenient input = <* skipSpace <* (endOfInput "trailing junk after valid JSON") --- | @either throwError return . eitherDecodeLenient@ +-- | @either throwE return . eitherDecodeLenient@ instance FromJSON a => MimeUnrender JSON a where - mimeUnrender _ = either throwError return . eitherDecodeLenient + mimeUnrender _ = either throwE return . eitherDecodeLenient --- | @either throwError return . (decodeFormUrlEncoded >=> fromFormUrlEncoded)@ +-- | @either throwE return . (decodeFormUrlEncoded >=> fromFormUrlEncoded)@ -- Note that the @mimeUnrender p (mimeRender p x) == Right x@ law only -- holds if every element of x is non-null (i.e., not @("", "")@) instance FromFormUrlEncoded a => MimeUnrender FormUrlEncoded a where - mimeUnrender _ = either throwError return . (decodeFormUrlEncoded >=> fromFormUrlEncoded) + mimeUnrender _ = either throwE return . (decodeFormUrlEncoded >=> fromFormUrlEncoded) --- | @either throwError return . left show . TextL.decodeUtf8'@ +-- | @either throwE return . left show . TextL.decodeUtf8'@ instance MimeUnrender PlainText TextL.Text where - mimeUnrender _ = either throwError return . left show . TextL.decodeUtf8' + mimeUnrender _ = either throwE return . left show . TextL.decodeUtf8' --- | @either throwError return . left show . TextS.decodeUtf8' . toStrict@ +-- | @either throwE return . left show . TextS.decodeUtf8' . toStrict@ instance MimeUnrender PlainText TextS.Text where - mimeUnrender _ = either throwError return . left show . TextS.decodeUtf8' . toStrict + mimeUnrender _ = either throwE return . left show . TextS.decodeUtf8' . toStrict -- | @return . BC.unpack@ instance MimeUnrender PlainText String where diff --git a/servant/test/Servant/API/ContentTypesSpec.hs b/servant/test/Servant/API/ContentTypesSpec.hs index 9dd9fa72d..cc7fa116c 100644 --- a/servant/test/Servant/API/ContentTypesSpec.hs +++ b/servant/test/Servant/API/ContentTypesSpec.hs @@ -14,9 +14,9 @@ import Data.Monoid import Data.Traversable #endif import Control.Arrow -import Control.Monad (when) -import Control.Monad.Except (runExceptT) -import Control.Monad.Trans (liftIO) +import Control.Monad (when) +import Control.Monad.Trans.Except (runExceptT) +import Control.Monad.IO.Class (liftIO) import Data.Aeson import Data.ByteString.Char8 (ByteString, append, pack) import qualified Data.ByteString.Lazy as BSL