Skip to content

Commit c836475

Browse files
author
Poscat
committed
Fix compatibility with older ghc versions
1 parent dcbcf15 commit c836475

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Data/Aeson/Types/FromJSON.hs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
{-# LANGUAGE FlexibleContexts #-}
55
{-# LANGUAGE FlexibleInstances #-}
66
{-# LANGUAGE GADTs #-}
7+
{-# LANGUAGE InstanceSigs #-}
78
{-# LANGUAGE MultiParamTypeClasses #-}
89
{-# LANGUAGE NoImplicitPrelude #-}
910
{-# LANGUAGE OverloadedStrings #-}
1011
{-# LANGUAGE PolyKinds #-}
1112
{-# LANGUAGE RecordWildCards #-}
1213
{-# LANGUAGE ScopedTypeVariables #-}
13-
{-# LANGUAGE TypeApplications #-}
1414
{-# LANGUAGE TypeOperators #-}
1515
{-# LANGUAGE TupleSections #-}
1616
{-# LANGUAGE UndecidableInstances #-}
@@ -159,8 +159,7 @@ import qualified Data.Primitive.Types as PM
159159
import qualified Data.Primitive.PrimArray as PM
160160

161161
import Data.Coerce (Coercible, coerce)
162-
import GHC.TypeNats
163-
import Data.Kind (Type)
162+
import GHC.TypeLits
164163

165164
parseIndexedJSON :: (Value -> Parser a) -> Int -> Value -> Parser a
166165
parseIndexedJSON p idx value = p value <?> Index idx
@@ -1434,12 +1433,15 @@ instance ( IsRecord f isRecord
14341433
, FromTaggedFlatObject' arity f isRecord
14351434
, Constructor c
14361435
) => FromTaggedFlatObject arity (C1 c f) where
1436+
parseTaggedFlatObject :: Text :* TypeName :* Options :* FromArgs arity a
1437+
-> Object
1438+
-> Maybe (Parser (C1 c f a))
14371439
parseTaggedFlatObject (tag :* p@(_ :* opts :* _)) obj
1438-
| tag == tag' = Just $ fmap M1 $ (unTagged @Type @isRecord) $ parseTaggedFlatObject' (cname :* p) obj
1440+
| tag == tag' = Just $ fmap M1 $ (unTagged :: Tagged isRecord (Parser (f a)) -> Parser (f a)) $ parseTaggedFlatObject' (cname :* p) obj
14391441
| otherwise = Nothing
14401442
where
14411443
tag' = pack $ constructorTagModifier opts cname
1442-
cname = conName (undefined :: M1 i c a p)
1444+
cname = conName (undefined :: M1 i c f p)
14431445

14441446
class FromTaggedFlatObject' arity f isRecord where
14451447
parseTaggedFlatObject' :: ConName :* TypeName :* Options :* FromArgs arity a
@@ -1453,7 +1455,7 @@ instance FromTaggedFlatObject' arity U1 False where
14531455
parseTaggedFlatObject' _ _ = Tagged (pure U1)
14541456

14551457
instance OVERLAPPABLE_ (PositionFromObject 1 arity f) => FromTaggedFlatObject' arity f False where
1456-
parseTaggedFlatObject' (_ :* p) obj = Tagged (positionFromObject (Proxy @1) p obj)
1458+
parseTaggedFlatObject' (_ :* p) obj = Tagged (positionFromObject (Proxy :: Proxy 1) p obj)
14571459

14581460
class KnownNat n => PositionFromObject n arity f where
14591461
positionFromObject :: Proxy n
@@ -1463,15 +1465,15 @@ class KnownNat n => PositionFromObject n arity f where
14631465

14641466
instance (KnownNat n, GFromJSON arity a) => PositionFromObject n arity (S1 m a) where
14651467
positionFromObject _ (_ :* opts :* fargs) obj =
1466-
explicitParseField (gParseJSON opts fargs) obj $ pack $ show $ natVal $ Proxy @n
1468+
explicitParseField (gParseJSON opts fargs) obj $ pack $ show $ natVal (Proxy :: Proxy n)
14671469

14681470
instance ( PositionFromObject n arity f
14691471
, PositionFromObject (n+1) arity g
14701472
) => PositionFromObject n arity (f :*: g) where
14711473
positionFromObject _ p obj =
14721474
(:*:)
1473-
<$> positionFromObject (Proxy @n) p obj
1474-
<*> positionFromObject (Proxy @(n+1)) p obj
1475+
<$> positionFromObject (Proxy :: Proxy n) p obj
1476+
<*> positionFromObject (Proxy :: Proxy (n+1)) p obj
14751477

14761478
--------------------------------------------------------------------------------
14771479

Data/Aeson/Types/ToJSON.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ import qualified Data.Primitive.Array as PM
142142
import qualified Data.Primitive.SmallArray as PM
143143
import qualified Data.Primitive.Types as PM
144144
import qualified Data.Primitive.PrimArray as PM
145-
import GHC.TypeNats
145+
import GHC.TypeLits
146146

147147
toJSONPair :: (a -> Value) -> (b -> Value) -> (a, b) -> Value
148148
toJSONPair a b = liftToJSON2 a (listValue a) b (listValue b)

0 commit comments

Comments
 (0)