Commits

Bryan O'Sullivan  committed 763f025

Add pervasive aeson support

  • Participants
  • Parent commits 5222a74

Comments (0)

Files changed (22)

File Statistics/Distribution/Beta.hs

   , bdBeta
   ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
    -- ^ Beta shape parameter
  } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON BetaDistribution
+instance ToJSON BetaDistribution
+
 instance Binary BetaDistribution where
     put (BD x y) = put x >> put y
     get = BD <$> get <*> get

File Statistics/Distribution/Binomial.hs

     , bdProbability
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
     -- ^ Probability.
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON BinomialDistribution
+instance ToJSON BinomialDistribution
+
 instance Binary BinomialDistribution where
     put (BD x y) = put x >> put y
     get = BD <$> get <*> get

File Statistics/Distribution/CauchyLorentz.hs

   , standardCauchy
   ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
   }
   deriving (Eq, Show, Read, Typeable, Data, Generic)
 
+instance FromJSON CauchyDistribution
+instance ToJSON CauchyDistribution
+
 instance Binary CauchyDistribution where
     put (CD x y) = put x >> put y
     get = CD <$> get <*> get

File Statistics/Distribution/ChiSquared.hs

         , chiSquaredNDF
         ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 newtype ChiSquared = ChiSquared Int
                      deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON ChiSquared
+instance ToJSON ChiSquared
+
 instance Binary ChiSquared where
     get = fmap ChiSquared get
     put (ChiSquared x) = put x

File Statistics/Distribution/Exponential.hs

     , edLambda
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
       edLambda :: Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON ExponentialDistribution
+instance ToJSON ExponentialDistribution
+
 instance Binary ExponentialDistribution where
     put = put . edLambda
     get = fmap ED get

File Statistics/Distribution/FDistribution.hs

   , fDistributionNDF2
   ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import Numeric.MathFunctions.Constants (m_neg_inf)
 import Data.Binary (put, get)
 import Control.Applicative ((<$>), (<*>))
 
-
-
 -- | F distribution
 data FDistribution = F { fDistributionNDF1 :: {-# UNPACK #-} !Double
                        , fDistributionNDF2 :: {-# UNPACK #-} !Double
                        }
                    deriving (Eq, Show, Read, Typeable, Data, Generic)
 
+instance FromJSON FDistribution
+instance ToJSON FDistribution
+
 instance Binary FDistribution where
     get = F <$> get <*> get <*> get
     put (F x y z) = put x >> put y >> put z

File Statistics/Distribution/Gamma.hs

     , gdScale
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Control.Applicative ((<$>), (<*>))
 import Data.Binary (Binary)
 import Data.Binary (put, get)
     , gdScale :: {-# UNPACK #-} !Double -- ^ Scale parameter, &#977;.
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON GammaDistribution
+instance ToJSON GammaDistribution
+
 instance Binary GammaDistribution where
     put (GD x y) = put x >> put y
     get = GD <$> get <*> get

File Statistics/Distribution/Geometric.hs

     , gdSuccess0
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Control.Applicative ((<$>))
 import Control.Monad (liftM)
 import Data.Binary (Binary)
       gdSuccess :: Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON GeometricDistribution
+instance ToJSON GeometricDistribution
+
 instance Binary GeometricDistribution where
     get = GD <$> get
     put (GD x) = put x
       gdSuccess0 :: Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON GeometricDistribution0
+instance ToJSON GeometricDistribution0
+
 instance Binary GeometricDistribution0 where
     get = GD0 <$> get
     put (GD0 x) = put x

File Statistics/Distribution/Hypergeometric.hs

     , hdK
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
     , hdK :: {-# UNPACK #-} !Int
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON HypergeometricDistribution
+instance ToJSON HypergeometricDistribution
+
 instance Binary HypergeometricDistribution where
     get = HD <$> get <*> get <*> get
     put (HD x y z) = put x >> put y >> put z

File Statistics/Distribution/Normal.hs

     , standard
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Control.Applicative ((<$>), (<*>))
 import Data.Binary (Binary)
 import Data.Binary (put, get)
 import qualified Statistics.Sample as S
 import qualified System.Random.MWC.Distributions as MWC
 
-
 -- | The normal distribution.
 data NormalDistribution = ND {
       mean       :: {-# UNPACK #-} !Double
     , ndCdfDenom :: {-# UNPACK #-} !Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON NormalDistribution
+instance ToJSON NormalDistribution
+
 instance Binary NormalDistribution where
     put (ND w x y z) = put w >> put x >> put y >> put z
     get = ND <$> get <*> get <*> get <*> get

File Statistics/Distribution/Poisson.hs

     -- $references
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
       poissonLambda :: Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON PoissonDistribution
+instance ToJSON PoissonDistribution
+
 instance Binary PoissonDistribution where
     get = fmap PD get
     put = put . poissonLambda

File Statistics/Distribution/StudentT.hs

   , studentTUnstandardized
   ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 newtype StudentT = StudentT { studentTndf :: Double }
                    deriving (Eq, Show, Read, Typeable, Data, Generic)
 
+instance FromJSON StudentT
+instance ToJSON StudentT
+
 instance Binary StudentT where
     put = put . studentTndf
     get = fmap StudentT get

File Statistics/Distribution/Transform.hs

     , scaleAround
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Control.Applicative ((<*>))
 import Data.Binary (Binary)
 import Data.Binary (put, get)
     -- ^ Distribution being transformed.
   } deriving (Eq, Show, Read, Typeable, Data, Generic)
 
+instance (FromJSON d) => FromJSON (LinearTransform d)
+instance (ToJSON d) => ToJSON (LinearTransform d)
+
 instance (Binary d) => Binary (LinearTransform d) where
     get = LinearTransform <$> get <*> get <*> get
     put (LinearTransform x y z) = put x >> put y >> put z

File Statistics/Distribution/Uniform.hs

     , uniformB
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
     , uniformB :: {-# UNPACK #-} !Double -- ^ Upper boundary of distribution
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON UniformDistribution
+instance ToJSON UniformDistribution
+
 instance Binary UniformDistribution where
     put (UniformDistribution x y) = put x >> put y
     get = UniformDistribution <$> get <*> get

File Statistics/Math/RootFinding.hs

     -- $references
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Control.Applicative (Alternative(..), Applicative(..))
 import Control.Monad (MonadPlus(..), ap)
 import Data.Binary (Binary)
             -- ^ A root was successfully found.
               deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance (FromJSON a) => FromJSON (Root a)
+instance (ToJSON a) => ToJSON (Root a)
+
 instance (Binary a) => Binary (Root a) where
     put NotBracketed = putWord8 0
     put SearchFailed = putWord8 1

File Statistics/Resampling.hs

     , estimate
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Control.Concurrent (forkIO, newChan, readChan, writeChan)
 import Control.Monad (forM_, liftM, replicateM_)
 import Control.Monad.Primitive (PrimState)
       fromResample :: U.Vector Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON Resample
+instance ToJSON Resample
+
 instance Binary Resample where
     put = put . fromResample
     get = fmap Resample get

File Statistics/Resampling/Bootstrap.hs

 import Control.DeepSeq (NFData)
 import Control.Exception (assert)
 import Control.Monad.Par (parMap, runPar)
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary)
 import Data.Binary (put, get)
 import Data.Data (Data)
     -- ^ Confidence level of the confidence intervals.
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON Estimate
+instance ToJSON Estimate
+
 instance Binary Estimate where
     put (Estimate w x y z) = put w >> put x >> put y >> put z
     get = Estimate <$> get <*> get <*> get <*> get

File Statistics/Sample/KernelDensity/Simple.hs

     -- $references
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary(..))
 import Data.Data (Data, Typeable)
 import Data.Vector.Binary ()
       fromPoints :: U.Vector Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON Points
+instance ToJSON Points
+
 instance Binary Points where
     get = fmap Points get
     put = put . fromPoints

File Statistics/Sample/Powers.hs

     -- $references
     ) where
 
+import Data.Aeson (FromJSON, ToJSON)
 import Data.Binary (Binary(..))
 import Data.Data (Data, Typeable)
 import Data.Vector.Binary ()
 newtype Powers = Powers (U.Vector Double)
     deriving (Eq, Read, Show, Typeable, Data, Generic)
 
+instance FromJSON Powers
+instance ToJSON Powers
+
 instance Binary Powers where
     put (Powers v) = put v
     get = fmap Powers get

File Statistics/Test/Types.hs

-{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
 module Statistics.Test.Types (
     TestType(..)
   , TestResult(..)
   , significant
   ) where
 
-import Data.Typeable (Typeable)
+import Data.Aeson (FromJSON, ToJSON)
+import Data.Data (Typeable, Data)
+import GHC.Generics
 
 
 -- | Test type. Exact meaning depends on a specific test. But
 -- for 'OneTailed' or whether it too big or too small for 'TwoTailed'
 data TestType = OneTailed
               | TwoTailed
-              deriving (Eq,Ord,Show,Typeable)
+              deriving (Eq,Ord,Show,Typeable,Data,Generic)
+
+instance FromJSON TestType
+instance ToJSON TestType
 
 -- | Result of hypothesis testing
 data TestResult = Significant    -- ^ Null hypothesis should be rejected
                 | NotSignificant -- ^ Data is compatible with hypothesis
-                  deriving (Eq,Ord,Show,Typeable)
+                  deriving (Eq,Ord,Show,Typeable,Data,Generic)
+
+instance FromJSON TestResult
+instance ToJSON TestResult
 
 -- | Significant if parameter is 'True', not significant otherwiser
 significant :: Bool -> TestResult

File changelog.md

+Changes in 0.13.0.0
+
+  * All types now support JSON encoding and decoding.
+
 Changes in 0.12.0.0
 
   * The `Statistics.Math` module has been removed, after being

File statistics.cabal

 name:           statistics
-version:        0.12.0.0
+version:        0.13.0.0
 synopsis:       A library of statistical types, data, and functions
 description:
   This library provides a number of common functions and types useful
     Statistics.Sample.Internal
     Statistics.Test.Internal
   build-depends:
+    aeson >= 0.6.0.0,
     base >= 4.4 && < 5,
     binary >= 0.5.1.0,
     deepseq >= 1.1.0.2,