Remove some conditionals for old versions

This commit is contained in:
Michael Snoyman 2017-12-12 12:08:06 +02:00
parent c122af25ad
commit c5ac821115
No known key found for this signature in database
GPG Key ID: A048E8C057E86876
9 changed files with 6 additions and 98 deletions

View File

@ -25,9 +25,7 @@ import Control.Monad.Trans.Identity ( IdentityT)
import Control.Monad.Trans.List ( ListT ) import Control.Monad.Trans.List ( ListT )
import Control.Monad.Trans.Maybe ( MaybeT ) import Control.Monad.Trans.Maybe ( MaybeT )
import Control.Monad.Trans.Error ( ErrorT, Error) import Control.Monad.Trans.Error ( ErrorT, Error)
#if MIN_VERSION_transformers(0,4,0)
import Control.Monad.Trans.Except ( ExceptT ) import Control.Monad.Trans.Except ( ExceptT )
#endif
import Control.Monad.Trans.Reader ( ReaderT ) import Control.Monad.Trans.Reader ( ReaderT )
import Control.Monad.Trans.State ( StateT ) import Control.Monad.Trans.State ( StateT )
import Control.Monad.Trans.Writer ( WriterT ) import Control.Monad.Trans.Writer ( WriterT )
@ -59,9 +57,7 @@ GO(IdentityT)
GO(ListT) GO(ListT)
GO(MaybeT) GO(MaybeT)
GOX(Error e, ErrorT e) GOX(Error e, ErrorT e)
#if MIN_VERSION_transformers(0,4,0)
GO(ExceptT e) GO(ExceptT e)
#endif
GO(ReaderT r) GO(ReaderT r)
GO(StateT s) GO(StateT s)
GOX(Monoid w, WriterT w) GOX(Monoid w, WriterT w)
@ -85,9 +81,7 @@ GO(IdentityT)
GO(ListT) GO(ListT)
GO(MaybeT) GO(MaybeT)
GOX(Error e, ErrorT e) GOX(Error e, ErrorT e)
#if MIN_VERSION_transformers(0,4,0)
GO(ExceptT e) GO(ExceptT e)
#endif
GO(ReaderT r) GO(ReaderT r)
GO(StateT s) GO(StateT s)
GOX(Monoid w, WriterT w) GOX(Monoid w, WriterT w)

View File

@ -66,12 +66,6 @@ import Data.Conduit.Internal (ResumableSource (ResumableSource))
import qualified Data.Conduit.Internal as CI import qualified Data.Conduit.Internal as CI
import qualified Data.Aeson as J import qualified Data.Aeson as J
#if MIN_VERSION_aeson(1, 0, 0)
#elif MIN_VERSION_aeson(0, 7, 0)
import Data.Aeson.Encode (encodeToTextBuilder)
#else
import Data.Aeson.Encode (fromValue)
#endif
import qualified Blaze.ByteString.Builder.Char.Utf8 as Blaze import qualified Blaze.ByteString.Builder.Char.Utf8 as Blaze
import Data.Text.Lazy.Builder (toLazyText) import Data.Text.Lazy.Builder (toLazyText)
import Yesod.Core.Types import Yesod.Core.Types
@ -243,34 +237,18 @@ instance ToContent a => ToContent (DontFullyEvaluate a) where
toContent (DontFullyEvaluate a) = ContentDontEvaluate $ toContent a toContent (DontFullyEvaluate a) = ContentDontEvaluate $ toContent a
instance ToContent J.Value where instance ToContent J.Value where
#if MIN_VERSION_aeson(1, 0, 0)
toContent = flip ContentBuilder Nothing toContent = flip ContentBuilder Nothing
. J.fromEncoding . J.fromEncoding
. J.toEncoding . J.toEncoding
#else
toContent = flip ContentBuilder Nothing
. Blaze.fromLazyText
. toLazyText
#if MIN_VERSION_aeson(0, 7, 0)
. encodeToTextBuilder
#else
. fromValue
#endif
#endif
#if MIN_VERSION_aeson(0, 11, 0)
instance ToContent J.Encoding where instance ToContent J.Encoding where
toContent = flip ContentBuilder Nothing . J.fromEncoding toContent = flip ContentBuilder Nothing . J.fromEncoding
#endif
instance HasContentType J.Value where instance HasContentType J.Value where
getContentType _ = typeJson getContentType _ = typeJson
#if MIN_VERSION_aeson(0, 11, 0)
instance HasContentType J.Encoding where instance HasContentType J.Encoding where
getContentType _ = typeJson getContentType _ = typeJson
#endif
instance HasContentType Html where instance HasContentType Html where
getContentType _ = typeHtml getContentType _ = typeHtml
@ -307,10 +285,8 @@ instance ToTypedContent RepXml where
toTypedContent (RepXml c) = TypedContent typeXml c toTypedContent (RepXml c) = TypedContent typeXml c
instance ToTypedContent J.Value where instance ToTypedContent J.Value where
toTypedContent v = TypedContent typeJson (toContent v) toTypedContent v = TypedContent typeJson (toContent v)
#if MIN_VERSION_aeson(0, 11, 0)
instance ToTypedContent J.Encoding where instance ToTypedContent J.Encoding where
toTypedContent e = TypedContent typeJson (toContent e) toTypedContent e = TypedContent typeJson (toContent e)
#endif
instance ToTypedContent Html where instance ToTypedContent Html where
toTypedContent h = TypedContent typeHtml (toContent h) toTypedContent h = TypedContent typeHtml (toContent h)
instance ToTypedContent T.Text where instance ToTypedContent T.Text where

View File

@ -635,11 +635,7 @@ sendResponseStatus s = handlerError . HCContent s . toTypedContent
-- --
-- @since 1.4.18 -- @since 1.4.18
sendStatusJSON :: (MonadHandler m, ToJSON c) => H.Status -> c -> m a sendStatusJSON :: (MonadHandler m, ToJSON c) => H.Status -> c -> m a
#if MIN_VERSION_aeson(0, 11, 0)
sendStatusJSON s v = sendResponseStatus s (toEncoding v) sendStatusJSON s v = sendResponseStatus s (toEncoding v)
#else
sendStatusJSON s v = sendResponseStatus s (toJSON v)
#endif
-- | Send a 201 "Created" response with the given route as the Location -- | Send a 201 "Created" response with the given route as the Location
-- response header. -- response header.

View File

@ -12,9 +12,6 @@ import Network.Wai
import Control.Monad (mplus) import Control.Monad (mplus)
import Control.Monad.Trans.Resource (runInternalState, InternalState) import Control.Monad.Trans.Resource (runInternalState, InternalState)
import Network.Wai.Internal import Network.Wai.Internal
#if !MIN_VERSION_base(4, 6, 0)
import Prelude hiding (catch)
#endif
import Web.Cookie (renderSetCookie) import Web.Cookie (renderSetCookie)
import Yesod.Core.Content import Yesod.Core.Content
import Yesod.Core.Types import Yesod.Core.Types

View File

@ -13,12 +13,7 @@ import Data.Serialize (Get, Put, Serialize (..))
import qualified Data.Text as T import qualified Data.Text as T
import Data.Time (Day (ModifiedJulianDay, toModifiedJulianDay), import Data.Time (Day (ModifiedJulianDay, toModifiedJulianDay),
DiffTime, UTCTime (..), formatTime, DiffTime, UTCTime (..), formatTime,
getCurrentTime, addUTCTime) getCurrentTime, addUTCTime, defaultTimeLocale)
#if MIN_VERSION_time(1,5,0)
import Data.Time (defaultTimeLocale)
#else
import System.Locale (defaultTimeLocale)
#endif
putTime :: UTCTime -> Put putTime :: UTCTime -> Put
putTime (UTCTime d t) = putTime (UTCTime d t) =

View File

@ -6,9 +6,7 @@ module Yesod.Core.Json
defaultLayoutJson defaultLayoutJson
, jsonToRepJson , jsonToRepJson
, returnJson , returnJson
#if MIN_VERSION_aeson(0, 11, 0)
, returnJsonEncoding , returnJsonEncoding
#endif
, provideJson , provideJson
-- * Convert to a JSON value -- * Convert to a JSON value
@ -29,9 +27,7 @@ module Yesod.Core.Json
-- * Convenience functions -- * Convenience functions
, jsonOrRedirect , jsonOrRedirect
#if MIN_VERSION_aeson(0, 11, 0)
, jsonEncodingOrRedirect , jsonEncodingOrRedirect
#endif
, acceptsJson , acceptsJson
) where ) where
@ -67,11 +63,7 @@ defaultLayoutJson :: (Yesod site, J.ToJSON a)
-> HandlerT site IO TypedContent -> HandlerT site IO TypedContent
defaultLayoutJson w json = selectRep $ do defaultLayoutJson w json = selectRep $ do
provideRep $ defaultLayout w provideRep $ defaultLayout w
#if MIN_VERSION_aeson(0, 11, 0)
provideRep $ fmap J.toEncoding json provideRep $ fmap J.toEncoding json
#else
provideRep $ fmap J.toJSON json
#endif
-- | Wraps a data type in a 'RepJson'. The data type must -- | Wraps a data type in a 'RepJson'. The data type must
-- support conversion to JSON via 'J.ToJSON'. -- support conversion to JSON via 'J.ToJSON'.
@ -87,24 +79,18 @@ jsonToRepJson = return . J.toJSON
returnJson :: (Monad m, J.ToJSON a) => a -> m J.Value returnJson :: (Monad m, J.ToJSON a) => a -> m J.Value
returnJson = return . J.toJSON returnJson = return . J.toJSON
#if MIN_VERSION_aeson(0, 11, 0)
-- | Convert a value to a JSON representation via aeson\'s 'J.toEncoding' function. -- | Convert a value to a JSON representation via aeson\'s 'J.toEncoding' function.
-- --
-- @since 1.4.21 -- @since 1.4.21
returnJsonEncoding :: (Monad m, J.ToJSON a) => a -> m J.Encoding returnJsonEncoding :: (Monad m, J.ToJSON a) => a -> m J.Encoding
returnJsonEncoding = return . J.toEncoding returnJsonEncoding = return . J.toEncoding
#endif
-- | Provide a JSON representation for usage with 'selectReps', using aeson\'s -- | Provide a JSON representation for usage with 'selectReps', using aeson\'s
-- 'J.toJSON' (aeson >= 0.11: 'J.toEncoding') function to perform the conversion. -- 'J.toJSON' (aeson >= 0.11: 'J.toEncoding') function to perform the conversion.
-- --
-- @since 1.2.1 -- @since 1.2.1
provideJson :: (Monad m, J.ToJSON a) => a -> Writer (Endo [ProvidedRep m]) () provideJson :: (Monad m, J.ToJSON a) => a -> Writer (Endo [ProvidedRep m]) ()
#if MIN_VERSION_aeson(0, 11, 0)
provideJson = provideRep . return . J.toEncoding provideJson = provideRep . return . J.toEncoding
#else
provideJson = provideRep . return . J.toJSON
#endif
-- | Parse the request body to a data type as a JSON value. The -- | Parse the request body to a data type as a JSON value. The
-- data type must support conversion from JSON via 'J.FromJSON'. -- data type must support conversion from JSON via 'J.FromJSON'.
@ -173,7 +159,6 @@ jsonOrRedirect :: (MonadHandler m, J.ToJSON a)
-> m J.Value -> m J.Value
jsonOrRedirect = jsonOrRedirect' J.toJSON jsonOrRedirect = jsonOrRedirect' J.toJSON
#if MIN_VERSION_aeson(0, 11, 0)
-- | jsonEncodingOrRedirect simplifies the scenario where a POST handler sends a different -- | jsonEncodingOrRedirect simplifies the scenario where a POST handler sends a different
-- response based on Accept headers: -- response based on Accept headers:
-- --
@ -187,7 +172,6 @@ jsonEncodingOrRedirect :: (MonadHandler m, J.ToJSON a)
-> a -- ^ Data to send via JSON -> a -- ^ Data to send via JSON
-> m J.Encoding -> m J.Encoding
jsonEncodingOrRedirect = jsonOrRedirect' J.toEncoding jsonEncodingOrRedirect = jsonOrRedirect' J.toEncoding
#endif
jsonOrRedirect' :: MonadHandler m jsonOrRedirect' :: MonadHandler m
=> (a -> b) => (a -> b)

View File

@ -59,16 +59,11 @@ import Yesod.Core.Internal.Util (getTime, putTime)
import Control.Monad.Trans.Class (MonadTrans (..)) import Control.Monad.Trans.Class (MonadTrans (..))
import Yesod.Routes.Class (RenderRoute (..), ParseRoute (..)) import Yesod.Routes.Class (RenderRoute (..), ParseRoute (..))
import Control.Monad.Reader (MonadReader (..)) import Control.Monad.Reader (MonadReader (..))
#if !MIN_VERSION_base(4, 6, 0)
import Prelude hiding (catch)
#endif
import Control.DeepSeq (NFData (rnf)) import Control.DeepSeq (NFData (rnf))
import Control.DeepSeq.Generics (genericRnf) import Control.DeepSeq.Generics (genericRnf)
import Data.Conduit.Lazy (MonadActive, monadActive) import Data.Conduit.Lazy (MonadActive, monadActive)
import Yesod.Core.TypeCache (TypeMap, KeyedTypeMap) import Yesod.Core.TypeCache (TypeMap, KeyedTypeMap)
#if MIN_VERSION_monad_logger(0, 3, 10)
import Control.Monad.Logger (MonadLoggerIO (..)) import Control.Monad.Logger (MonadLoggerIO (..))
#endif
import Data.Semigroup (Semigroup) import Data.Semigroup (Semigroup)
-- Sessions -- Sessions
@ -422,21 +417,12 @@ instance MonadIO m => MonadIO (WidgetT site m) where
instance MonadBase b m => MonadBase b (WidgetT site m) where instance MonadBase b m => MonadBase b (WidgetT site m) where
liftBase = WidgetT . const . liftBase . fmap (, mempty) liftBase = WidgetT . const . liftBase . fmap (, mempty)
instance MonadBaseControl b m => MonadBaseControl b (WidgetT site m) where instance MonadBaseControl b m => MonadBaseControl b (WidgetT site m) where
#if MIN_VERSION_monad_control(1,0,0)
type StM (WidgetT site m) a = StM m (a, GWData (Route site)) type StM (WidgetT site m) a = StM m (a, GWData (Route site))
liftBaseWith f = WidgetT $ \reader' -> liftBaseWith f = WidgetT $ \reader' ->
liftBaseWith $ \runInBase -> liftBaseWith $ \runInBase ->
fmap (\x -> (x, mempty)) fmap (\x -> (x, mempty))
(f $ runInBase . flip unWidgetT reader') (f $ runInBase . flip unWidgetT reader')
restoreM = WidgetT . const . restoreM restoreM = WidgetT . const . restoreM
#else
data StM (WidgetT site m) a = StW (StM m (a, GWData (Route site)))
liftBaseWith f = WidgetT $ \reader' ->
liftBaseWith $ \runInBase ->
fmap (\x -> (x, mempty))
(f $ fmap StW . runInBase . flip unWidgetT reader')
restoreM (StW base) = WidgetT $ const $ restoreM base
#endif
instance Monad m => MonadReader site (WidgetT site m) where instance Monad m => MonadReader site (WidgetT site m) where
ask = WidgetT $ \hd -> return (rheSite $ handlerEnv hd, mempty) ask = WidgetT $ \hd -> return (rheSite $ handlerEnv hd, mempty)
local f (WidgetT g) = WidgetT $ \hd -> g hd local f (WidgetT g) = WidgetT $ \hd -> g hd
@ -479,10 +465,8 @@ instance MonadIO m => MonadLogger (WidgetT site m) where
monadLoggerLog a b c d = WidgetT $ \hd -> monadLoggerLog a b c d = WidgetT $ \hd ->
liftIO $ (, mempty) <$> rheLog (handlerEnv hd) a b c (toLogStr d) liftIO $ (, mempty) <$> rheLog (handlerEnv hd) a b c (toLogStr d)
#if MIN_VERSION_monad_logger(0, 3, 10)
instance MonadIO m => MonadLoggerIO (WidgetT site m) where instance MonadIO m => MonadLoggerIO (WidgetT site m) where
askLoggerIO = WidgetT $ \hd -> return (rheLog (handlerEnv hd), mempty) askLoggerIO = WidgetT $ \hd -> return (rheLog (handlerEnv hd), mempty)
#endif
instance MonadActive m => MonadActive (WidgetT site m) where instance MonadActive m => MonadActive (WidgetT site m) where
monadActive = lift monadActive monadActive = lift monadActive
@ -521,19 +505,11 @@ instance Monad m => MonadReader site (HandlerT site m) where
-- \"Control.Monad.Trans.Resource.register\': The mutable state is being accessed -- \"Control.Monad.Trans.Resource.register\': The mutable state is being accessed
-- after cleanup. Please contact the maintainers.\" -- after cleanup. Please contact the maintainers.\"
instance MonadBaseControl b m => MonadBaseControl b (HandlerT site m) where instance MonadBaseControl b m => MonadBaseControl b (HandlerT site m) where
#if MIN_VERSION_monad_control(1,0,0)
type StM (HandlerT site m) a = StM m a type StM (HandlerT site m) a = StM m a
liftBaseWith f = HandlerT $ \reader' -> liftBaseWith f = HandlerT $ \reader' ->
liftBaseWith $ \runInBase -> liftBaseWith $ \runInBase ->
f $ runInBase . (\(HandlerT r) -> r reader') f $ runInBase . (\(HandlerT r) -> r reader')
restoreM = HandlerT . const . restoreM restoreM = HandlerT . const . restoreM
#else
data StM (HandlerT site m) a = StH (StM m a)
liftBaseWith f = HandlerT $ \reader' ->
liftBaseWith $ \runInBase ->
f $ fmap StH . runInBase . (\(HandlerT r) -> r reader')
restoreM (StH base) = HandlerT $ const $ restoreM base
#endif
instance MonadThrow m => MonadThrow (HandlerT site m) where instance MonadThrow m => MonadThrow (HandlerT site m) where
throwM = lift . monadThrow throwM = lift . monadThrow
@ -545,10 +521,8 @@ instance MonadIO m => MonadLogger (HandlerT site m) where
monadLoggerLog a b c d = HandlerT $ \hd -> monadLoggerLog a b c d = HandlerT $ \hd ->
liftIO $ rheLog (handlerEnv hd) a b c (toLogStr d) liftIO $ rheLog (handlerEnv hd) a b c (toLogStr d)
#if MIN_VERSION_monad_logger(0, 3, 10)
instance MonadIO m => MonadLoggerIO (HandlerT site m) where instance MonadIO m => MonadLoggerIO (HandlerT site m) where
askLoggerIO = HandlerT $ \hd -> return (rheLog (handlerEnv hd)) askLoggerIO = HandlerT $ \hd -> return (rheLog (handlerEnv hd))
#endif
instance Monoid (UniqueList x) where instance Monoid (UniqueList x) where
mempty = UniqueList id mempty = UniqueList id

View File

@ -30,11 +30,7 @@ data MyApp = MyApp
data MySub = MySub data MySub = MySub
instance RenderRoute MySub where instance RenderRoute MySub where
data data
#if MIN_VERSION_base(4,5,0)
Route Route
#else
YRC.Route
#endif
MySub = MySubRoute ([Text], [(Text, Text)]) MySub = MySubRoute ([Text], [(Text, Text)])
deriving (Show, Eq, Read) deriving (Show, Eq, Read)
renderRoute (MySubRoute x) = x renderRoute (MySubRoute x) = x
@ -47,11 +43,7 @@ getMySub MyApp = MySub
data MySubParam = MySubParam Int data MySubParam = MySubParam Int
instance RenderRoute MySubParam where instance RenderRoute MySubParam where
data data
#if MIN_VERSION_base(4,5,0)
Route Route
#else
YRC.Route
#endif
MySubParam = ParamRoute Char MySubParam = ParamRoute Char
deriving (Show, Eq, Read) deriving (Show, Eq, Read)
renderRoute (ParamRoute x) = ([singleton x], []) renderRoute (ParamRoute x) = ([singleton x], [])

View File

@ -22,7 +22,7 @@ extra-source-files:
library library
build-depends: base >= 4.7 && < 5 build-depends: base >= 4.7 && < 5
, time >= 1.1.4 , time >= 1.5
, wai >= 3.0 , wai >= 3.0
, wai-extra >= 3.0.7 , wai-extra >= 3.0.7
, bytestring >= 0.10 , bytestring >= 0.10
@ -31,7 +31,7 @@ library
, path-pieces >= 0.1.2 && < 0.3 , path-pieces >= 0.1.2 && < 0.3
, shakespeare >= 2.0 , shakespeare >= 2.0
, blaze-builder >= 0.2.1.4 && < 0.5 , blaze-builder >= 0.2.1.4 && < 0.5
, transformers >= 0.2.2 , transformers >= 0.4
, mtl , mtl
, clientsession >= 0.9.1 && < 0.10 , clientsession >= 0.9.1 && < 0.10
, random >= 1.0.0.2 && < 1.2 , random >= 1.0.0.2 && < 1.2
@ -39,7 +39,7 @@ library
, old-locale >= 1.0.0.2 && < 1.1 , old-locale >= 1.0.0.2 && < 1.1
, containers >= 0.2 , containers >= 0.2
, unordered-containers >= 0.2 , unordered-containers >= 0.2
, monad-control >= 0.3 && < 1.1 , monad-control >= 1.0 && < 1.1
, transformers-base >= 0.4 , transformers-base >= 0.4
, cookie >= 0.4.2 && < 0.5 , cookie >= 0.4.2 && < 0.5
, http-types >= 0.7 , http-types >= 0.7
@ -47,10 +47,10 @@ library
, parsec >= 2 && < 3.2 , parsec >= 2 && < 3.2
, directory >= 1 , directory >= 1
, vector >= 0.9 && < 0.13 , vector >= 0.9 && < 0.13
, aeson >= 0.5 , aeson >= 1.0
, fast-logger >= 2.2 , fast-logger >= 2.2
, wai-logger >= 0.2 , wai-logger >= 0.2
, monad-logger >= 0.3.1 && < 0.4 , monad-logger >= 0.3.10 && < 0.4
, conduit >= 1.2 , conduit >= 1.2
, resourcet >= 0.4.9 && < 1.2 , resourcet >= 0.4.9 && < 1.2
, lifted-base >= 0.1.2 , lifted-base >= 0.1.2