Skip to content

Commit

Permalink
Fix compatibility with older ghc versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Poscat committed Jan 19, 2021
1 parent dcbcf15 commit a24c404
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions Data/Aeson/Types/FromJSON.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
Expand All @@ -10,7 +11,6 @@
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE UndecidableInstances #-}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

--------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion Data/Aeson/Types/ToJSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a24c404

Please sign in to comment.