From a24c404444eef117a25bf247ca86312f107dd124 Mon Sep 17 00:00:00 2001 From: Poscat Date: Tue, 19 Jan 2021 23:05:07 +0800 Subject: [PATCH] Fix compatibility with older ghc versions --- Data/Aeson/Types/FromJSON.hs | 17 ++++++++--------- Data/Aeson/Types/ToJSON.hs | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Data/Aeson/Types/FromJSON.hs b/Data/Aeson/Types/FromJSON.hs index b4c65fe78..363b17a66 100644 --- a/Data/Aeson/Types/FromJSON.hs +++ b/Data/Aeson/Types/FromJSON.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE PartialTypeSignatures #-} {-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DefaultSignatures #-} @@ -10,7 +11,6 @@ {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE UndecidableInstances #-} @@ -159,8 +159,7 @@ import qualified Data.Primitive.Types as PM import qualified Data.Primitive.PrimArray as PM import Data.Coerce (Coercible, coerce) -import GHC.TypeNats -import Data.Kind (Type) +import GHC.TypeLits parseIndexedJSON :: (Value -> Parser a) -> Int -> Value -> Parser a parseIndexedJSON p idx value = p value Index idx @@ -1435,11 +1434,11 @@ instance ( IsRecord f isRecord , Constructor c ) => FromTaggedFlatObject arity (C1 c f) where parseTaggedFlatObject (tag :* p@(_ :* opts :* _)) obj - | tag == tag' = Just $ fmap M1 $ (unTagged @Type @isRecord) $ parseTaggedFlatObject' (cname :* p) obj + | tag == tag' = Just $ fmap M1 $ (unTagged :: Tagged isRecord _ -> _) $ parseTaggedFlatObject' (cname :* p) obj | otherwise = Nothing where tag' = pack $ constructorTagModifier opts cname - cname = conName (undefined :: M1 i c a p) + cname = conName (undefined :: M1 i c f p) class FromTaggedFlatObject' arity f isRecord where parseTaggedFlatObject' :: ConName :* TypeName :* Options :* FromArgs arity a @@ -1453,7 +1452,7 @@ instance FromTaggedFlatObject' arity U1 False where parseTaggedFlatObject' _ _ = Tagged (pure U1) instance OVERLAPPABLE_ (PositionFromObject 1 arity f) => FromTaggedFlatObject' arity f False where - parseTaggedFlatObject' (_ :* p) obj = Tagged (positionFromObject (Proxy @1) p obj) + parseTaggedFlatObject' (_ :* p) obj = Tagged (positionFromObject (Proxy :: Proxy 1) p obj) class KnownNat n => PositionFromObject n arity f where positionFromObject :: Proxy n @@ -1463,15 +1462,15 @@ class KnownNat n => PositionFromObject n arity f where instance (KnownNat n, GFromJSON arity a) => PositionFromObject n arity (S1 m a) where positionFromObject _ (_ :* opts :* fargs) obj = - explicitParseField (gParseJSON opts fargs) obj $ pack $ show $ natVal $ Proxy @n + explicitParseField (gParseJSON opts fargs) obj $ pack $ show $ natVal (Proxy :: Proxy n) instance ( PositionFromObject n arity f , PositionFromObject (n+1) arity g ) => PositionFromObject n arity (f :*: g) where positionFromObject _ p obj = (:*:) - <$> positionFromObject (Proxy @n) p obj - <*> positionFromObject (Proxy @(n+1)) p obj + <$> positionFromObject (Proxy :: Proxy n) p obj + <*> positionFromObject (Proxy :: Proxy (n+1)) p obj -------------------------------------------------------------------------------- diff --git a/Data/Aeson/Types/ToJSON.hs b/Data/Aeson/Types/ToJSON.hs index bf791e74e..5f9c09d69 100644 --- a/Data/Aeson/Types/ToJSON.hs +++ b/Data/Aeson/Types/ToJSON.hs @@ -142,7 +142,7 @@ import qualified Data.Primitive.Array as PM import qualified Data.Primitive.SmallArray as PM import qualified Data.Primitive.Types as PM import qualified Data.Primitive.PrimArray as PM -import GHC.TypeNats +import GHC.TypeLits toJSONPair :: (a -> Value) -> (b -> Value) -> (a, b) -> Value toJSONPair a b = liftToJSON2 a (listValue a) b (listValue b)