fixed-vector-aeson 2.0.0.0 → 2.1.0.0
raw patch · 2 files changed
+31/−18 lines, 2 filesdep ~basedep ~fixed-vectorPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, fixed-vector
API changes (from Hackage documentation)
+ Data.Vector.Fixed.Instances.Aeson: instance (Data.Vector.Fixed.Mono.Prod a v, Data.Aeson.Types.FromJSON.FromJSON a) => Data.Aeson.Types.FromJSON.FromJSON (Data.Vector.Fixed.Mono.ViaFixed a v)
+ Data.Vector.Fixed.Instances.Aeson: instance (Data.Vector.Fixed.Mono.Prod a v, Data.Aeson.Types.ToJSON.ToJSON a) => Data.Aeson.Types.ToJSON.ToJSON (Data.Vector.Fixed.Mono.ViaFixed a v)
- Data.Vector.Fixed.Instances.Aeson: fixedVectorParseJSON :: (Vector v a, FromJSON a) => Value -> Parser (v a)
+ Data.Vector.Fixed.Instances.Aeson: fixedVectorParseJSON :: forall v a. (Prod a v, FromJSON a) => Value -> Parser v
- Data.Vector.Fixed.Instances.Aeson: fixedVectorToEncoding :: (Vector v a, ToJSON a) => v a -> Encoding
+ Data.Vector.Fixed.Instances.Aeson: fixedVectorToEncoding :: forall v a. (Prod a v, ToJSON a) => v -> Encoding
- Data.Vector.Fixed.Instances.Aeson: fixedVectorToJSON :: (Vector v a, ToJSON a) => v a -> Value
+ Data.Vector.Fixed.Instances.Aeson: fixedVectorToJSON :: forall v a. (Prod a v, ToJSON a) => v -> Value
Files
Data/Vector/Fixed/Instances/Aeson.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-}+{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-}@@ -22,8 +23,10 @@ import qualified Data.Vector.Fixed.Unboxed as FU import qualified Data.Vector.Fixed.Primitive as FP import qualified Data.Vector.Fixed.Storable as FS+import qualified Data.Vector.Fixed.Mono as FM import Data.Aeson import Data.Aeson.Types+import Data.Coerce import qualified Data.Vector as V import qualified Data.Vector.Mutable as MV@@ -35,32 +38,32 @@ -- | Generic implementation of 'parseJSON' for data types which are -- instances of 'Vector'.-fixedVectorParseJSON :: forall v a. (Vector v a, FromJSON a) => Value -> Parser (v a)+fixedVectorParseJSON :: forall v a. (FM.Prod a v, FromJSON a) => Value -> Parser v {-# INLINE fixedVectorParseJSON #-} fixedVectorParseJSON = withArray "fixed-vector" $ \arr -> do- let expected = F.length (undefined :: v a)+ let expected = FM.length (undefined :: v) when (V.length arr /= expected) $ fail $ "Expecting array of length " ++ show expected- F.generateM $ \i -> parseJSON (arr V.! i)+ coerce $ FM.generateM @(FM.ViaFixed a v) $ \i -> parseJSON (arr V.! i) -- | Generic implementation of 'toJSON' for data types which are -- instances of 'Vector'.-fixedVectorToJSON :: forall v a. (Vector v a, ToJSON a) => v a -> Value+fixedVectorToJSON :: forall v a. (FM.Prod a v, ToJSON a) => v -> Value {-# INLINE fixedVectorToJSON #-} fixedVectorToJSON v = Array $ runST $ do -- NOTE: (!) from fixed vector could have O(n) complexity so let -- fold over fixed vector. Access to vector _is_ O(1) vec <- MV.unsafeNew n- flip F.imapM_ v $ \i a -> MV.unsafeWrite vec i (toJSON a)+ flip FM.imapM_ (FM.ViaFixed v) $ \i a -> MV.unsafeWrite vec i (toJSON a) V.unsafeFreeze vec where- n = F.length v+ n = FM.length v -- | Generic implementation of 'toEncoding' for data types which are -- instances of 'Vector'.-fixedVectorToEncoding :: forall v a. (Vector v a, ToJSON a) => v a -> Encoding+fixedVectorToEncoding :: forall v a. (FM.Prod a v, ToJSON a) => v -> Encoding {-# INLINE fixedVectorToEncoding #-}-fixedVectorToEncoding = foldable . F.cvec+fixedVectorToEncoding = foldable . FM.cvec ----------------------------------------------------------------@@ -68,10 +71,21 @@ ---------------------------------------------------------------- instance (Vector v a, FromJSON a) => FromJSON (ViaFixed v a) where+ parseJSON = fixedVectorParseJSON {-# INLINE parseJSON #-}++instance (FM.Prod a v, FromJSON a) => FromJSON (FM.ViaFixed a v) where parseJSON = fixedVectorParseJSON+ {-# INLINE parseJSON #-} + instance (Vector v a, ToJSON a) => ToJSON (ViaFixed v a) where+ toJSON = fixedVectorToJSON+ toEncoding = fixedVectorToEncoding+ {-# INLINE toJSON #-}+ {-# INLINE toEncoding #-}++instance (FM.Prod a v, ToJSON a) => ToJSON (FM.ViaFixed a v) where toJSON = fixedVectorToJSON toEncoding = fixedVectorToEncoding {-# INLINE toJSON #-}
fixed-vector-aeson.cabal view
@@ -1,5 +1,5 @@ Name: fixed-vector-aeson-Version: 2.0.0.0+Version: 2.1.0.0 Synopsis: Aeson instances for fixed-vector Description: This package contains FromJSON and ToJSON instances for data types defined in@@ -17,13 +17,12 @@ ChangeLog.md tested-with:- GHC ==8.10.7- || ==9.0.1- || ==9.2.8- || ==9.4.7- || ==9.6.6- || ==9.8.2- || ==9.10.1+ GHC ==9.4.7+ || ==9.6.7+ || ==9.8.4+ || ==9.10.2+ || ==9.12.2+ || ==9.14.1 source-repository head type: git@@ -32,8 +31,8 @@ Library Ghc-options: -Wall Default-Language: Haskell2010- Build-Depends: base >=4.14 && <5- , fixed-vector >=2.0+ Build-Depends: base >=4.16 && <5+ , fixed-vector >=2.1 , aeson >=2 , vector Exposed-modules: