summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexeyKhudyakov <>2017-05-17 17:21:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-05-17 17:21:00 (GMT)
commit7fef61cf8998c98034de8480a7207ce665c3bb8c (patch)
treefa85c7961bd673c393d67445639a644c96e121b7
parent6d08dca5993fefbb429cacd41f6331e33d60ba47 (diff)
version 0.14.0.10.14.0.1
-rw-r--r--Statistics/Internal.hs1
-rw-r--r--Statistics/Resampling.hs15
-rw-r--r--Statistics/Test/Types.hs25
-rw-r--r--Statistics/Types.hs38
-rw-r--r--changelog.md5
-rw-r--r--statistics.cabal6
-rw-r--r--tests/Tests/Serialization.hs14
7 files changed, 82 insertions, 22 deletions
diff --git a/Statistics/Internal.hs b/Statistics/Internal.hs
index 30fbdbe..f639e52 100644
--- a/Statistics/Internal.hs
+++ b/Statistics/Internal.hs
@@ -25,6 +25,7 @@ module Statistics.Internal (
import Control.Applicative
import Control.Monad
import Text.Read
+import Data.Orphans ()
diff --git a/Statistics/Resampling.hs b/Statistics/Resampling.hs
index 4eb0116..caaf170 100644
--- a/Statistics/Resampling.hs
+++ b/Statistics/Resampling.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFunctor #-}
@@ -37,7 +38,7 @@ module Statistics.Resampling
import Data.Aeson (FromJSON, ToJSON)
import Control.Applicative
import Control.Concurrent (forkIO, newChan, readChan, writeChan)
-import Control.Monad (forM_, forM, replicateM, replicateM_)
+import Control.Monad (forM_, forM, replicateM, replicateM_, liftM2)
import Control.Monad.Primitive (PrimMonad(..))
import Data.Binary (Binary(..))
import Data.Data (Data, Typeable)
@@ -82,9 +83,15 @@ data Bootstrap v a = Bootstrap
{ fullSample :: !a
, resamples :: v a
}
- deriving (Eq, Read, Show, Typeable, Data, Generic, Functor, T.Foldable, T.Traversable)
-
-instance (Binary a, Binary (v a)) => Binary (Bootstrap v a)
+ deriving (Eq, Read, Show , Generic, Functor, T.Foldable, T.Traversable
+#if __GLASGOW_HASKELL >= 708
+ , Typeable, Data
+#endif
+ )
+
+instance (Binary a, Binary (v a)) => Binary (Bootstrap v a) where
+ get = liftM2 Bootstrap get get
+ put (Bootstrap fs rs) = put fs >> put rs
instance (FromJSON a, FromJSON (v a)) => FromJSON (Bootstrap v a)
instance (ToJSON a, ToJSON (v a)) => ToJSON (Bootstrap v a)
diff --git a/Statistics/Test/Types.hs b/Statistics/Test/Types.hs
index 9dfa8eb..c03d35c 100644
--- a/Statistics/Test/Types.hs
+++ b/Statistics/Test/Types.hs
@@ -8,8 +8,9 @@ module Statistics.Test.Types (
) where
import Control.DeepSeq (NFData(..))
+import Control.Monad (liftM3)
import Data.Aeson (FromJSON, ToJSON)
-import Data.Binary (Binary)
+import Data.Binary (Binary (..))
import Data.Data (Typeable, Data)
import GHC.Generics
@@ -21,7 +22,11 @@ data TestResult = Significant -- ^ Null hypothesis should be rejected
| NotSignificant -- ^ Data is compatible with hypothesis
deriving (Eq,Ord,Show,Typeable,Data,Generic)
-instance Binary TestResult
+instance Binary TestResult where
+ get = do
+ sig <- get
+ if sig then return Significant else return NotSignificant
+ put = put . (== Significant)
instance FromJSON TestResult
instance ToJSON TestResult
instance NFData TestResult
@@ -40,7 +45,9 @@ data Test distr = Test
}
deriving (Eq,Ord,Show,Typeable,Data,Generic,Functor)
-instance (Binary d) => Binary (Test d)
+instance (Binary d) => Binary (Test d) where
+ get = liftM3 Test get get get
+ put (Test sign stat distr) = put sign >> put stat >> put distr
instance (FromJSON d) => FromJSON (Test d)
instance (ToJSON d) => ToJSON (Test d)
instance (NFData d) => NFData (Test d) where
@@ -65,7 +72,17 @@ data PositionTest
-- ^ Test if second sample is larger than first.
deriving (Eq,Ord,Show,Typeable,Data,Generic)
-instance Binary PositionTest
+instance Binary PositionTest where
+ get = do
+ i <- get
+ case (i :: Int) of
+ 0 -> return SamplesDiffer
+ 1 -> return AGreater
+ 2 -> return BGreater
+ _ -> fail "Invalid PositionTest"
+ put SamplesDiffer = put (0 :: Int)
+ put AGreater = put (1 :: Int)
+ put BGreater = put (2 :: Int)
instance FromJSON PositionTest
instance ToJSON PositionTest
instance NFData PositionTest
diff --git a/Statistics/Types.hs b/Statistics/Types.hs
index bd7d3ca..aeff0e1 100644
--- a/Statistics/Types.hs
+++ b/Statistics/Types.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
@@ -62,7 +63,7 @@ module Statistics.Types
, Weights
) where
-import Control.Monad ((<=<))
+import Control.Monad ((<=<), liftM2, liftM3)
import Control.DeepSeq (NFData(..))
import Data.Aeson (FromJSON(..), ToJSON)
import Data.Binary (Binary(..))
@@ -70,7 +71,12 @@ import Data.Data (Data,Typeable)
import Data.Maybe (fromMaybe)
import Data.Vector.Unboxed (Unbox)
import Data.Vector.Unboxed.Deriving (derivingUnbox)
-import GHC.Generics (Generic)
+import GHC.Generics (Generic)
+
+#if __GLASGOW_HASKELL__ == 704
+import qualified Data.Vector.Generic
+import qualified Data.Vector.Generic.Mutable
+#endif
import Statistics.Internal
import Statistics.Types.Internal
@@ -317,9 +323,15 @@ data Estimate e a = Estimate
-- ^ Point estimate.
, estError :: !(e a)
-- ^ Confidence interval for estimate.
- } deriving (Eq, Read, Show, Typeable, Data, Generic)
-
-instance (Binary (e a), Binary a) => Binary (Estimate e a)
+ } deriving (Eq, Read, Show, Generic
+#if __GLASGOW_HASKELL >= 708
+ , Typeable, Data
+#endif
+ )
+
+instance (Binary (e a), Binary a) => Binary (Estimate e a) where
+ get = liftM2 Estimate get get
+ put (Estimate ep ee) = put ep >> put ee
instance (FromJSON (e a), FromJSON a) => FromJSON (Estimate e a)
instance (ToJSON (e a), ToJSON a) => ToJSON (Estimate e a)
instance (NFData (e a), NFData a) => NFData (Estimate e a) where
@@ -336,7 +348,9 @@ newtype NormalErr a = NormalErr
}
deriving (Eq, Read, Show, Typeable, Data, Generic)
-instance Binary a => Binary (NormalErr a)
+instance Binary a => Binary (NormalErr a) where
+ get = fmap NormalErr get
+ put = put . normalError
instance FromJSON a => FromJSON (NormalErr a)
instance ToJSON a => ToJSON (NormalErr a)
instance NFData a => NFData (NormalErr a) where
@@ -357,7 +371,9 @@ data ConfInt a = ConfInt
}
deriving (Read,Show,Eq,Typeable,Data,Generic)
-instance Binary a => Binary (ConfInt a)
+instance Binary a => Binary (ConfInt a) where
+ get = liftM3 ConfInt get get get
+ put (ConfInt l u cl) = put l >> put u >> put cl
instance FromJSON a => FromJSON (ConfInt a)
instance ToJSON a => ToJSON (ConfInt a)
instance NFData a => NFData (ConfInt a) where
@@ -445,7 +461,9 @@ data UpperLimit a = UpperLimit
} deriving (Eq, Read, Show, Typeable, Data, Generic)
-instance Binary a => Binary (UpperLimit a)
+instance Binary a => Binary (UpperLimit a) where
+ get = liftM2 UpperLimit get get
+ put (UpperLimit l cl) = put l >> put cl
instance FromJSON a => FromJSON (UpperLimit a)
instance ToJSON a => ToJSON (UpperLimit a)
instance NFData a => NFData (UpperLimit a) where
@@ -462,7 +480,9 @@ data LowerLimit a = LowerLimit {
-- ^ Confidence level for which limit was calculated
} deriving (Eq, Read, Show, Typeable, Data, Generic)
-instance Binary a => Binary (LowerLimit a)
+instance Binary a => Binary (LowerLimit a) where
+ get = liftM2 LowerLimit get get
+ put (LowerLimit l cl) = put l >> put cl
instance FromJSON a => FromJSON (LowerLimit a)
instance ToJSON a => ToJSON (LowerLimit a)
instance NFData a => NFData (LowerLimit a) where
diff --git a/changelog.md b/changelog.md
index 082c69b..581db43 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,8 @@
+## Changes in 0.14.0.1
+
+ * Restored compatibility with GHC 7.4 & 7.6
+
+
## Changes in 0.14.0.0
Breaking update. It seriously changes parts of API. It adds new data types for
diff --git a/statistics.cabal b/statistics.cabal
index 056ce96..963d5d1 100644
--- a/statistics.cabal
+++ b/statistics.cabal
@@ -1,5 +1,5 @@
name: statistics
-version: 0.14.0.0
+version: 0.14.0.1
synopsis: A library of statistical types, data, and functions
description:
This library provides a number of common functions and types useful
@@ -44,7 +44,8 @@ extra-source-files:
tests/Tests/Math/gen.py
tests/utils/Makefile
tests/utils/fftw.c
-
+tested-with: GHC==7.6.3, GHC==7.8.3, GHC==7.10.3, GHC==8.0.1
+
library
exposed-modules:
Statistics.Autocorrelation
@@ -103,6 +104,7 @@ library
build-depends:
aeson >= 0.6.0.0,
base >= 4.4 && < 5,
+ base-orphans >= 0.6 && <0.7,
binary >= 0.5.1.0,
deepseq >= 1.1.0.2,
erf,
diff --git a/tests/Tests/Serialization.hs b/tests/Tests/Serialization.hs
index 3de21c9..c2a02ff 100644
--- a/tests/Tests/Serialization.hs
+++ b/tests/Tests/Serialization.hs
@@ -39,8 +39,8 @@ tests = testGroup "Test for data serialization"
, serializationTests (T :: T (PValue Double))
, serializationTests (T :: T (NormalErr Double))
, serializationTests (T :: T (ConfInt Double))
- , serializationTests (T :: T (Estimate NormalErr Double))
- , serializationTests (T :: T (Estimate ConfInt Double))
+ , serializationTests' "T (Estimate NormalErr Double)" (T :: T (Estimate NormalErr Double))
+ , serializationTests' "T (Estimate ConfInt Double)" (T :: T (Estimate ConfInt Double))
, serializationTests (T :: T (LowerLimit Double))
, serializationTests (T :: T (UpperLimit Double))
-- Distributions
@@ -66,12 +66,20 @@ tests = testGroup "Test for data serialization"
serializationTests
:: (Eq a, Typeable a, Binary a, Show a, Read a, ToJSON a, FromJSON a, Arbitrary a)
=> T a -> Test
-serializationTests t = testGroup ("Tests for: " ++ typeName t)
+serializationTests t = serializationTests' (typeName t) t
+
+-- Not all types are Typeable, unfortunately
+serializationTests'
+ :: (Eq a, Binary a, Show a, Read a, ToJSON a, FromJSON a, Arbitrary a)
+ => String -> T a -> Test
+serializationTests' name t = testGroup ("Tests for: " ++ name)
[ testProperty "show/read" (p_showRead t)
, testProperty "binary" (p_binary t)
, testProperty "aeson" (p_aeson t)
]
+
+
p_binary :: (Eq a, Binary a) => T a -> a -> Bool
p_binary _ a = a == (decode . encode) a