From 6e97e60b7c23ec453006bdfb931e63bf11201806 Mon Sep 17 00:00:00 2001 From: L0neGamer Date: Wed, 20 Sep 2023 22:55:10 +0100 Subject: [PATCH 1/3] bumping aeson and making compilation work --- Duckling/AmountOfMoney/Types.hs | 12 +++++++++--- Duckling/Distance/Types.hs | 12 +++++++++--- Duckling/Duration/Types.hs | 10 +++++++++- Duckling/Quantity/Types.hs | 13 ++++++++++--- Duckling/Temperature/Types.hs | 12 +++++++++--- Duckling/Time/Corpus.hs | 12 +++++++++--- Duckling/Time/Types.hs | 18 ++++++++++++------ Duckling/Volume/Types.hs | 12 +++++++++--- duckling.cabal | 2 +- 9 files changed, 77 insertions(+), 26 deletions(-) diff --git a/Duckling/AmountOfMoney/Types.hs b/Duckling/AmountOfMoney/Types.hs index 803c4ff2a..dc9c4cb24 100644 --- a/Duckling/AmountOfMoney/Types.hs +++ b/Duckling/AmountOfMoney/Types.hs @@ -11,6 +11,7 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE CPP #-} module Duckling.AmountOfMoney.Types where @@ -20,7 +21,12 @@ import Data.Hashable import Data.Text (Text) import GHC.Generics import Prelude -import qualified Data.HashMap.Strict as H + +# if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as KM +# else +import qualified Data.HashMap.Strict as KM +# endif import Duckling.Resolve (Resolve(..), Options(..)) @@ -204,8 +210,8 @@ data AmountOfMoneyValue instance ToJSON AmountOfMoneyValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object KM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Distance/Types.hs b/Duckling/Distance/Types.hs index 1432665a0..eadb01f85 100644 --- a/Duckling/Distance/Types.hs +++ b/Duckling/Distance/Types.hs @@ -11,6 +11,7 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE CPP #-} module Duckling.Distance.Types where @@ -20,9 +21,14 @@ import Data.Hashable import Data.Text (Text) import GHC.Generics import Prelude -import qualified Data.HashMap.Strict as H import qualified Data.Text as Text +# if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as KM +# else +import qualified Data.HashMap.Strict as KM +# endif + import Duckling.Resolve (Resolve(..)) data Unit @@ -86,8 +92,8 @@ data DistanceValue instance ToJSON DistanceValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object KM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Duration/Types.hs b/Duckling/Duration/Types.hs index b24b2affc..fd2f52527 100644 --- a/Duckling/Duration/Types.hs +++ b/Duckling/Duration/Types.hs @@ -11,6 +11,7 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE CPP #-} module Duckling.Duration.Types where @@ -27,6 +28,13 @@ import Prelude import Duckling.Resolve (Resolve(..)) import Duckling.TimeGrain.Types (Grain(..), inSeconds) +# if MIN_VERSION_aeson(2, 0, 0) +import Data.Aeson.Key (fromText) +# else +fromText :: Text -> Text +fromText = id +# endif + data DurationData = DurationData { value :: Int , grain :: Grain @@ -48,7 +56,7 @@ instance ToJSON DurationData where [ "type" .= ("value" :: Text) , "value" .= value , "unit" .= grain - , showt grain .= value + , fromText (showt grain) .= value , "normalized" .= object [ "unit" .= ("second" :: Text) , "value" .= inSeconds grain value diff --git a/Duckling/Quantity/Types.hs b/Duckling/Quantity/Types.hs index 657bbcc51..570c1771b 100644 --- a/Duckling/Quantity/Types.hs +++ b/Duckling/Quantity/Types.hs @@ -10,11 +10,12 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE CPP #-} + module Duckling.Quantity.Types where import Control.DeepSeq import Data.Aeson -import qualified Data.HashMap.Strict as H import Data.Hashable import Data.Text (Text) import qualified Data.Text as Text @@ -25,6 +26,12 @@ import Duckling.Resolve import GHC.Generics import Prelude +# if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as KM +# else +import qualified Data.HashMap.Strict as KM +# endif + data Unit = Bowl | Cup @@ -118,8 +125,8 @@ data QuantityValue instance ToJSON QuantityValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object KM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Temperature/Types.hs b/Duckling/Temperature/Types.hs index 43ec337d8..67e042215 100644 --- a/Duckling/Temperature/Types.hs +++ b/Duckling/Temperature/Types.hs @@ -11,6 +11,7 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE CPP #-} module Duckling.Temperature.Types where @@ -20,9 +21,14 @@ import Data.Hashable import Data.Text (Text) import GHC.Generics import Prelude -import qualified Data.HashMap.Strict as H import qualified Data.Text as Text +# if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as KM +# else +import qualified Data.HashMap.Strict as KM +# endif + import Duckling.Resolve (Resolve(..)) data TemperatureUnit = @@ -76,8 +82,8 @@ data TemperatureValue instance ToJSON TemperatureValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object KM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Time/Corpus.hs b/Duckling/Time/Corpus.hs index c1e6b293f..69648c7b6 100644 --- a/Duckling/Time/Corpus.hs +++ b/Duckling/Time/Corpus.hs @@ -7,6 +7,7 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE CPP #-} module Duckling.Time.Corpus ( datetime @@ -18,12 +19,17 @@ module Duckling.Time.Corpus ) where import Data.Aeson -import qualified Data.HashMap.Strict as H import Data.Text (Text) import qualified Data.Time.LocalTime.TimeZone.Series as Series import Prelude import Data.String +# if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as KM +# else +import qualified Data.HashMap.Strict as KM +# endif + import Duckling.Resolve import Duckling.Testing.Types hiding (examples) import Duckling.Time.Types hiding (Month) @@ -71,8 +77,8 @@ check f context Resolved{rval = RVal _ v} = case toJSON v of _ -> False where deleteValues :: Value -> Value - deleteValues (Object o) = Object $ H.delete "values" o - deleteValues _ = Object H.empty + deleteValues (Object o) = Object $ KM.delete "values" o + deleteValues _ = Object KM.empty examples :: ToJSON a => (Context -> a) -> [Text] -> [Example] examples f = examplesCustom (check f) diff --git a/Duckling/Time/Types.hs b/Duckling/Time/Types.hs index da66c6734..caae6e857 100644 --- a/Duckling/Time/Types.hs +++ b/Duckling/Time/Types.hs @@ -13,6 +13,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE CPP #-} module Duckling.Time.Types where @@ -27,13 +28,18 @@ import Data.Tuple.Extra (both) import GHC.Generics hiding (from, to) import Prelude import TextShow (showt) -import qualified Data.HashMap.Strict as H import qualified Data.List as List import qualified Data.Text as Text import qualified Data.Time as Time import qualified Data.Time.Calendar.WeekDate as Time import qualified Data.Time.LocalTime.TimeZone.Series as Series +# if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as KM +# else +import qualified Data.HashMap.Strict as KM +# endif + import Duckling.Resolve import Duckling.TimeGrain.Types (Grain) import qualified Duckling.TimeGrain.Types as TG @@ -180,8 +186,8 @@ instance ToJSON InstantValue where instance ToJSON SingleTimeValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object KM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from @@ -199,12 +205,12 @@ instance ToJSON SingleTimeValue where instance ToJSON TimeValue where toJSON (TimeValue value values holiday) = case toJSON value of Object o -> - Object $ insertHoliday holiday $ H.insert "values" (toJSON values) o - _ -> Object H.empty + Object $ insertHoliday holiday $ KM.insert "values" (toJSON values) o + _ -> Object KM.empty where insertHoliday :: Maybe Text -> Object -> Object insertHoliday Nothing obj = obj - insertHoliday (Just h) obj = H.insert "holidayBeta" (toJSON h) obj + insertHoliday (Just h) obj = KM.insert "holidayBeta" (toJSON h) obj -- | Return a tuple of (past, future) elements type SeriesPredicate = TimeObject -> TimeContext -> ([TimeObject], [TimeObject]) diff --git a/Duckling/Volume/Types.hs b/Duckling/Volume/Types.hs index 7c515f9a4..306ca46cb 100644 --- a/Duckling/Volume/Types.hs +++ b/Duckling/Volume/Types.hs @@ -11,6 +11,7 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE CPP #-} module Duckling.Volume.Types where @@ -22,7 +23,12 @@ import GHC.Generics import Prelude import Duckling.Resolve (Resolve (..)) import qualified Data.Text as Text -import qualified Data.HashMap.Strict as H + +# if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as KM +# else +import qualified Data.HashMap.Strict as KM +# endif data Unit = Gallon @@ -81,8 +87,8 @@ data VolumeValue instance ToJSON VolumeValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object KM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/duckling.cabal b/duckling.cabal index ca1f25b30..5f5ee8f67 100644 --- a/duckling.cabal +++ b/duckling.cabal @@ -879,7 +879,7 @@ library build-depends: , base >= 4.8.2 && < 5.0 , array >= 0.5.1.1 && < 0.6 , attoparsec >= 0.13.1.0 && < 0.15 - , aeson >= 0.11.3.0 && < 1.6 + , aeson >= 0.11.3.0 && < 2.2.0.0 , bytestring >= 0.10.6.0 && < 0.12 , containers >= 0.5.6.2 && < 0.7 , deepseq >= 1.4.1.1 && < 1.5 From 605b0a56c020b2bc0a77e584daac46d7155bea9b Mon Sep 17 00:00:00 2001 From: L0neGamer Date: Wed, 20 Sep 2023 22:57:39 +0100 Subject: [PATCH 2/3] relax aeson upper bound --- duckling.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/duckling.cabal b/duckling.cabal index 5f5ee8f67..1bd98985d 100644 --- a/duckling.cabal +++ b/duckling.cabal @@ -879,7 +879,7 @@ library build-depends: , base >= 4.8.2 && < 5.0 , array >= 0.5.1.1 && < 0.6 , attoparsec >= 0.13.1.0 && < 0.15 - , aeson >= 0.11.3.0 && < 2.2.0.0 + , aeson >= 0.11.3.0 && < 2.3.0.0 , bytestring >= 0.10.6.0 && < 0.12 , containers >= 0.5.6.2 && < 0.7 , deepseq >= 1.4.1.1 && < 1.5 From cfc38b48330ce7e35fb61808135e9e0e0457bfe1 Mon Sep 17 00:00:00 2001 From: L0neGamer Date: Sat, 23 Dec 2023 11:03:30 +0000 Subject: [PATCH 3/3] take comments on board, use mempty and a Compat module to reduce on CPP use --- Duckling/AmountOfMoney/Types.hs | 11 +++-------- Duckling/Compat.hs | 20 ++++++++++++++++++++ Duckling/Distance/Types.hs | 11 +++-------- Duckling/Duration/Types.hs | 11 +++-------- Duckling/Quantity/Types.hs | 12 ++++-------- Duckling/Temperature/Types.hs | 12 ++++-------- Duckling/Time/Corpus.hs | 12 ++++-------- Duckling/Time/Types.hs | 18 +++++++----------- Duckling/Volume/Types.hs | 11 +++-------- duckling.cabal | 1 + 10 files changed, 52 insertions(+), 67 deletions(-) create mode 100644 Duckling/Compat.hs diff --git a/Duckling/AmountOfMoney/Types.hs b/Duckling/AmountOfMoney/Types.hs index dc9c4cb24..43ef30c9f 100644 --- a/Duckling/AmountOfMoney/Types.hs +++ b/Duckling/AmountOfMoney/Types.hs @@ -11,7 +11,6 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE CPP #-} module Duckling.AmountOfMoney.Types where @@ -22,11 +21,7 @@ import Data.Text (Text) import GHC.Generics import Prelude -# if MIN_VERSION_aeson(2, 0, 0) -import qualified Data.Aeson.KeyMap as KM -# else -import qualified Data.HashMap.Strict as KM -# endif +import qualified Duckling.Compat as Compat import Duckling.Resolve (Resolve(..), Options(..)) @@ -210,8 +205,8 @@ data AmountOfMoneyValue instance ToJSON AmountOfMoneyValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o - _ -> Object KM.empty + Object o -> Object $ Compat.insert "type" (toJSON ("value" :: Text)) o + _ -> Object mempty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Compat.hs b/Duckling/Compat.hs new file mode 100644 index 000000000..5df48a89e --- /dev/null +++ b/Duckling/Compat.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE CPP #-} + +module Duckling.Compat + ( KM.insert + , KM.delete + , fromText + ) where + +# if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.KeyMap as KM +# else +import qualified Data.HashMap.Strict as KM +# endif + +# if MIN_VERSION_aeson(2, 0, 0) +import Data.Aeson.Key (fromText) +# else +fromText :: Text -> Text +fromText = id +# endif diff --git a/Duckling/Distance/Types.hs b/Duckling/Distance/Types.hs index eadb01f85..1bc6911bb 100644 --- a/Duckling/Distance/Types.hs +++ b/Duckling/Distance/Types.hs @@ -11,7 +11,6 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE CPP #-} module Duckling.Distance.Types where @@ -23,11 +22,7 @@ import GHC.Generics import Prelude import qualified Data.Text as Text -# if MIN_VERSION_aeson(2, 0, 0) -import qualified Data.Aeson.KeyMap as KM -# else -import qualified Data.HashMap.Strict as KM -# endif +import qualified Duckling.Compat as Compat import Duckling.Resolve (Resolve(..)) @@ -92,8 +87,8 @@ data DistanceValue instance ToJSON DistanceValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o - _ -> Object KM.empty + Object o -> Object $ Compat.insert "type" (toJSON ("value" :: Text)) o + _ -> Object mempty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Duration/Types.hs b/Duckling/Duration/Types.hs index fd2f52527..52c9abf8a 100644 --- a/Duckling/Duration/Types.hs +++ b/Duckling/Duration/Types.hs @@ -11,7 +11,7 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE CPP #-} + module Duckling.Duration.Types where @@ -28,12 +28,7 @@ import Prelude import Duckling.Resolve (Resolve(..)) import Duckling.TimeGrain.Types (Grain(..), inSeconds) -# if MIN_VERSION_aeson(2, 0, 0) -import Data.Aeson.Key (fromText) -# else -fromText :: Text -> Text -fromText = id -# endif +import qualified Duckling.Compat as Compat data DurationData = DurationData { value :: Int @@ -56,7 +51,7 @@ instance ToJSON DurationData where [ "type" .= ("value" :: Text) , "value" .= value , "unit" .= grain - , fromText (showt grain) .= value + , Compat.fromText (showt grain) .= value , "normalized" .= object [ "unit" .= ("second" :: Text) , "value" .= inSeconds grain value diff --git a/Duckling/Quantity/Types.hs b/Duckling/Quantity/Types.hs index 570c1771b..25f5391eb 100644 --- a/Duckling/Quantity/Types.hs +++ b/Duckling/Quantity/Types.hs @@ -10,7 +10,7 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE CPP #-} + module Duckling.Quantity.Types where @@ -26,11 +26,7 @@ import Duckling.Resolve import GHC.Generics import Prelude -# if MIN_VERSION_aeson(2, 0, 0) -import qualified Data.Aeson.KeyMap as KM -# else -import qualified Data.HashMap.Strict as KM -# endif +import qualified Duckling.Compat as Compat data Unit = Bowl @@ -125,8 +121,8 @@ data QuantityValue instance ToJSON QuantityValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o - _ -> Object KM.empty + Object o -> Object $ Compat.insert "type" (toJSON ("value" :: Text)) o + _ -> Object mempty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Temperature/Types.hs b/Duckling/Temperature/Types.hs index 67e042215..f85840ccf 100644 --- a/Duckling/Temperature/Types.hs +++ b/Duckling/Temperature/Types.hs @@ -11,7 +11,7 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE CPP #-} + module Duckling.Temperature.Types where @@ -23,11 +23,7 @@ import GHC.Generics import Prelude import qualified Data.Text as Text -# if MIN_VERSION_aeson(2, 0, 0) -import qualified Data.Aeson.KeyMap as KM -# else -import qualified Data.HashMap.Strict as KM -# endif +import qualified Duckling.Compat as Compat import Duckling.Resolve (Resolve(..)) @@ -82,8 +78,8 @@ data TemperatureValue instance ToJSON TemperatureValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o - _ -> Object KM.empty + Object o -> Object $ Compat.insert "type" (toJSON ("value" :: Text)) o + _ -> Object mempty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Time/Corpus.hs b/Duckling/Time/Corpus.hs index 69648c7b6..3e0d5f817 100644 --- a/Duckling/Time/Corpus.hs +++ b/Duckling/Time/Corpus.hs @@ -7,7 +7,7 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE CPP #-} + module Duckling.Time.Corpus ( datetime @@ -24,11 +24,7 @@ import qualified Data.Time.LocalTime.TimeZone.Series as Series import Prelude import Data.String -# if MIN_VERSION_aeson(2, 0, 0) -import qualified Data.Aeson.KeyMap as KM -# else -import qualified Data.HashMap.Strict as KM -# endif +import qualified Duckling.Compat as Compat import Duckling.Resolve import Duckling.Testing.Types hiding (examples) @@ -77,8 +73,8 @@ check f context Resolved{rval = RVal _ v} = case toJSON v of _ -> False where deleteValues :: Value -> Value - deleteValues (Object o) = Object $ KM.delete "values" o - deleteValues _ = Object KM.empty + deleteValues (Object o) = Object $ Compat.delete "values" o + deleteValues _ = Object mempty examples :: ToJSON a => (Context -> a) -> [Text] -> [Example] examples f = examplesCustom (check f) diff --git a/Duckling/Time/Types.hs b/Duckling/Time/Types.hs index caae6e857..5ed99b46c 100644 --- a/Duckling/Time/Types.hs +++ b/Duckling/Time/Types.hs @@ -13,7 +13,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE CPP #-} + module Duckling.Time.Types where @@ -34,11 +34,7 @@ import qualified Data.Time as Time import qualified Data.Time.Calendar.WeekDate as Time import qualified Data.Time.LocalTime.TimeZone.Series as Series -# if MIN_VERSION_aeson(2, 0, 0) -import qualified Data.Aeson.KeyMap as KM -# else -import qualified Data.HashMap.Strict as KM -# endif +import qualified Duckling.Compat as Compat import Duckling.Resolve import Duckling.TimeGrain.Types (Grain) @@ -186,8 +182,8 @@ instance ToJSON InstantValue where instance ToJSON SingleTimeValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o - _ -> Object KM.empty + Object o -> Object $ Compat.insert "type" (toJSON ("value" :: Text)) o + _ -> Object mempty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from @@ -205,12 +201,12 @@ instance ToJSON SingleTimeValue where instance ToJSON TimeValue where toJSON (TimeValue value values holiday) = case toJSON value of Object o -> - Object $ insertHoliday holiday $ KM.insert "values" (toJSON values) o - _ -> Object KM.empty + Object $ insertHoliday holiday $ Compat.insert "values" (toJSON values) o + _ -> Object mempty where insertHoliday :: Maybe Text -> Object -> Object insertHoliday Nothing obj = obj - insertHoliday (Just h) obj = KM.insert "holidayBeta" (toJSON h) obj + insertHoliday (Just h) obj = Compat.insert "holidayBeta" (toJSON h) obj -- | Return a tuple of (past, future) elements type SeriesPredicate = TimeObject -> TimeContext -> ([TimeObject], [TimeObject]) diff --git a/Duckling/Volume/Types.hs b/Duckling/Volume/Types.hs index 306ca46cb..9d7b4239a 100644 --- a/Duckling/Volume/Types.hs +++ b/Duckling/Volume/Types.hs @@ -11,7 +11,6 @@ {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE CPP #-} module Duckling.Volume.Types where @@ -24,11 +23,7 @@ import Prelude import Duckling.Resolve (Resolve (..)) import qualified Data.Text as Text -# if MIN_VERSION_aeson(2, 0, 0) -import qualified Data.Aeson.KeyMap as KM -# else -import qualified Data.HashMap.Strict as KM -# endif +import qualified Duckling.Compat as Compat data Unit = Gallon @@ -87,8 +82,8 @@ data VolumeValue instance ToJSON VolumeValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ KM.insert "type" (toJSON ("value" :: Text)) o - _ -> Object KM.empty + Object o -> Object $ Compat.insert "type" (toJSON ("value" :: Text)) o + _ -> Object mempty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/duckling.cabal b/duckling.cabal index 1bd98985d..fa0ca8ebf 100644 --- a/duckling.cabal +++ b/duckling.cabal @@ -896,6 +896,7 @@ library build-depends: , regex-pcre-builtin >= 0.94.4 && < 0.96 else build-depends: , regex-pcre >= 0.94.4 && < 0.96 + other-modules: Duckling.Compat default-language: Haskell2010 default-extensions: OverloadedStrings