approximate 0.2.2.1 → 0.3.5
raw patch · 14 files changed
Files
- .gitignore +19/−0
- .hlint.yaml +4/−0
- .travis.yml +0/−31
- CHANGELOG.markdown +38/−0
- HLint.hs +0/−1
- README.markdown +1/−1
- Setup.lhs +4/−52
- approximate.cabal +29/−51
- src/Data/Approximate/Mass.hs +34/−18
- src/Data/Approximate/Numerics.hs +6/−1
- src/Data/Approximate/Type.hs +24/−14
- tests/doctests.hsc +0/−74
- travis/cabal-apt-install +0/−27
- travis/config +0/−16
.gitignore view
@@ -1,4 +1,5 @@ dist+dist-newstyle docs wiki TAGS@@ -11,3 +12,21 @@ *.hi *~ *#+.stack-work/+cabal-dev+*.chi+*.chs.h+*.dyn_o+*.dyn_hi+.hpc+.hsenv+.cabal-sandbox/+cabal.sandbox.config+*.prof+*.aux+*.hp+*.eventlog+cabal.project.local+cabal.project.local~+.HTF/+.ghc.environment.*
+ .hlint.yaml view
@@ -0,0 +1,4 @@+- arguments: [--cpp-ansi]++- ignore: {name: Use import/export shortcut}+- ignore: {name: Use fmap}
− .travis.yml
@@ -1,31 +0,0 @@-language: haskell-before_install:- # Uncomment whenever hackage is down.- # - mkdir -p ~/.cabal && cp travis/config ~/.cabal/config && cabal update- - cabal update-- # Try installing some of the build-deps with apt-get for speed.- - travis/cabal-apt-install $mode- - cabal install packdeps packunused- - export PATH=~/.cabal/bin:$PATH--install:- - cabal configure -flib-Werror $mode- - cabal build--script:- - $script- - packdeps approximate.cabal- - packunused- - hlint src --cpp-define HLINT--notifications:- irc:- channels:- - "irc.freenode.org#haskell-lens"- skip_join: true- template:- - "\x0313approximate\x03/\x0306%{branch}\x03 \x0314%{commit}\x03 %{build_url} %{message}"--env:- - mode="--enable-tests" script="cabal test --show-details=always"
CHANGELOG.markdown view
@@ -1,3 +1,41 @@+0.3.5 [2021.11.16]+------------------+* Add `Eq1` instances for `Approximate` and `Mass`.+* Allow building with `hashable-1.4.*`.+* Drop support for pre-8.0 versions of GHC.++0.3.4 [2021.02.21]+------------------+* Fix the build with `safecopy-0.10.4` or later.++0.3.3 [2021.02.17]+------------------+* Allow building with `lens-5.*`.+* The build-type has been changed from `Custom` to `Simple`.+ To achieve this, the `doctests` test suite has been removed in favor of using+ [`cabal-docspec`](https://github.com/phadej/cabal-extras/tree/master/cabal-docspec)+ to run the doctests.++0.3.2 [2019.09.13]+------------------+* Allow building with `safecopy-0.10`.++0.3.1+-----+* Add a library dependency on the `doctests` test suite++0.3+---+* Replace use of `Hashable1` from `hashable-extras` in favor of `Hashable` from+ `hashable-1.2.5.0`. As a result, the `hashable-extras` dependency has been removed.+* Revamp `Setup.hs` to use `cabal-doctest`. This makes it build+ with `Cabal-2.0`, and makes the `doctest`s work with `cabal new-build` and+ sandboxes.++0.2.2.3+-------+* Added support for `safecopy` 0.9 and `cereal` 0.5+ 0.2.2.1 ------- * Compiles warning-free on GHC 7.10
− HLint.hs
@@ -1,1 +0,0 @@-ignore "Use import/export shortcut"
README.markdown view
@@ -1,7 +1,7 @@ approximate =========== -[](http://travis-ci.org/ekmett/approximate)+[](https://hackage.haskell.org/package/approximate) [](https://github.com/ekmett/approximate/actions?query=workflow%3AHaskell-CI) This package provides approximate numbers and discrete values with lower bounds on their probability of correctness.
Setup.lhs view
@@ -1,55 +1,7 @@ #!/usr/bin/runhaskell-\begin{code}-{-# OPTIONS_GHC -Wall #-}-module Main (main) where--import Data.List ( nub )-import Data.Version ( showVersion )-import Distribution.Package ( PackageName(PackageName), Package, PackageId, InstalledPackageId, packageVersion, packageName )-import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )-import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )-import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose, copyFiles )-import Distribution.Simple.BuildPaths ( autogenModulesDir )-import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), Flag(..), fromFlag, HaddockFlags(haddockDistPref))-import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )-import Distribution.Text ( display )-import Distribution.Verbosity ( Verbosity, normal )-import System.FilePath ( (</>) )--main :: IO ()-main = defaultMainWithHooks simpleUserHooks- { buildHook = \pkg lbi hooks flags -> do- generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi- buildHook simpleUserHooks pkg lbi hooks flags- , postHaddock = \args flags pkg lbi -> do- copyFiles normal (haddockOutputDir flags pkg) []- postHaddock simpleUserHooks args flags pkg lbi- }--haddockOutputDir :: Package p => HaddockFlags -> p -> FilePath-haddockOutputDir flags pkg = destDir where- baseDir = case haddockDistPref flags of- NoFlag -> "."- Flag x -> x- destDir = baseDir </> "doc" </> "html" </> display (packageName pkg)--generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()-generateBuildModule verbosity pkg lbi = do- let dir = autogenModulesDir lbi- createDirectoryIfMissingVerbose verbosity True dir- withLibLBI pkg lbi $ \_ libcfg -> do- withTestLBI pkg lbi $ \suite suitecfg -> do- rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines- [ "module Build_" ++ testName suite ++ " where"- , "deps :: [String]"- , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))- ]- where- formatdeps = map (formatone . snd)- formatone p = case packageName p of- PackageName n -> n ++ "-" ++ showVersion (packageVersion p)+> module Main (main) where -testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]-testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys+> import Distribution.Simple -\end{code}+> main :: IO ()+> main = defaultMain
approximate.cabal view
@@ -1,8 +1,8 @@ name: approximate category: Numeric-version: 0.2.2.1+version: 0.3.5 license: BSD3-cabal-version: >= 1.8+cabal-version: >= 1.10 license-file: LICENSE author: Edward A. Kmett maintainer: Edward A. Kmett <ekmett@gmail.com>@@ -10,87 +10,65 @@ homepage: http://github.com/analytics/approximate/ bug-reports: http://github.com/analytics/approximate/issues copyright: Copyright (C) 2013 Edward A. Kmett-build-type: Custom-tested-with: GHC == 7.4.1, GHC == 7.6.1, GHC == 7.8.4, GHC == 7.10.1+build-type: Simple+tested-with: GHC == 8.0.2+ , GHC == 8.2.2+ , GHC == 8.4.4+ , GHC == 8.6.5+ , GHC == 8.8.4+ , GHC == 8.10.7+ , GHC == 9.0.1+ , GHC == 9.2.1 synopsis: Approximate discrete values and numbers description: This package provides approximate discrete values and numbers. extra-source-files:- .travis.yml .ghci .gitignore+ .hlint.yaml .vim.custom- travis/cabal-apt-install- travis/config AUTHORS.markdown README.markdown CHANGELOG.markdown- HLint.hs source-repository head type: git location: git://github.com/analytics/approximate.git --- You can disable the doctests test suite with -f-test-doctests-flag test-doctests- default: True- manual: True--flag lib-Werror+flag herbie default: False manual: True library build-depends:- base >= 4.3 && < 5,- binary >= 0.5 && < 0.8,+ base >= 4.9 && < 5,+ binary >= 0.5 && < 0.9, bytes >= 0.7 && < 1,- cereal >= 0.3.5 && < 0.5,- comonad >= 3 && < 5,+ cereal >= 0.3.5 && < 0.6,+ comonad >= 3 && < 6, deepseq >= 1.3 && < 1.5, ghc-prim,- hashable >= 1.1.2.3 && < 1.3,- hashable-extras >= 0.1 && < 1,- lens >= 3.9 && < 5,+ hashable >= 1.2.5 && < 1.5,+ lens >= 3.9 && < 6, log-domain,- pointed >= 3 && < 5,+ pointed >= 3 && < 6, semigroupoids >= 3.0.2 && < 6, semigroups >= 0.8.4 && < 1,- safecopy >= 0.8.1 && < 0.9,- vector >= 0.9 && < 0.11+ safecopy >= 0.8.1 && < 0.11,+ vector >= 0.12.1.2 && < 0.13 + if flag(herbie)+ build-depends: HerbiePlugin >= 0.1 && < 0.2+ cpp-options: -DHERBIE+ ghc-options: -fplugin=Herbie+ exposed-modules: Data.Approximate Data.Approximate.Type Data.Approximate.Mass Data.Approximate.Numerics - if flag(lib-Werror)- ghc-options: -Werror-- if impl(ghc >= 7.4 && < 7.6)- build-depends: ghc-prim- c-sources: cbits/fast.c- ghc-options: -Wall -fwarn-tabs -O2+ ghc-options: -Wall -Wtabs -O2 hs-source-dirs: src--test-suite doctests- type: exitcode-stdio-1.0- main-is: doctests.hs- ghc-options: -Wall -threaded- hs-source-dirs: tests-- if !flag(test-doctests)- buildable: False- else- build-depends:- base,- directory >= 1.0,- doctest >= 0.9.1,- filepath,- semigroups >= 0.9,- simple-reflect >= 0.3.1-- if impl(ghc<7.6.1) && flag(lib-Werror)- ghc-options: -Werror+ default-language: Haskell2010
src/Data/Approximate/Mass.hs view
@@ -17,9 +17,6 @@ , (|?), (&?), (^?) ) where -#if __GLASGOW_HASKELL__ < 710-import Control.Applicative-#endif import Control.Comonad import Control.DeepSeq import Control.Monad@@ -27,26 +24,27 @@ import Data.Bytes.Serial as Bytes import Data.Copointed import Data.Data-#if __GLASGOW_HASKELL__ < 710-import Data.Foldable-#endif import Data.Functor.Bind+import Data.Functor.Classes import Data.Functor.Extend-import Data.Hashable-import Data.Hashable.Extras+import Data.Hashable (Hashable(..))+import Data.Hashable.Lifted (Hashable1(..)) import Data.Pointed import Data.SafeCopy+#if !(MIN_VERSION_base(4,11,0)) import Data.Semigroup-import Data.Serialize as Serialize-#if __GLASGOW_HASKELL__ < 710-import Data.Traversable #endif-import Data.Vector.Generic as G-import Data.Vector.Generic.Mutable as M-import Data.Vector.Unboxed as U+import Data.Serialize as Serialize+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Generic.Mutable as M+import qualified Data.Vector.Unboxed as U+import Data.Vector.Unboxed (Unbox) import GHC.Generics import Numeric.Log +-- $setup+-- >>> import Control.Monad (replicateM)+ -- | A quantity with a lower-bound on its probability mass. This represents -- a 'probable value' as a 'Monad' that you can use to calculate progressively -- less likely consequences.@@ -63,8 +61,13 @@ -- Also note that @('&?')@ and @('|?')@ are able to use knowledge about the -- function to get better precision on their results than naively using -- @'liftA2' ('&&')@+--+-- >>> let z = Mass 0.875 'z'+-- >>> replicateM 3 z+-- Mass 0.669921875 "zzz"+-- data Mass a = Mass {-# UNPACK #-} !(Log Double) a- deriving (Eq,Ord,Show,Read,Typeable,Data,Generic)+ deriving (Eq,Ord,Show,Read,Data,Generic) instance Binary a => Binary (Mass a) where put (Mass p a) = Binary.put p >> Binary.put a@@ -74,10 +77,19 @@ put (Mass p a) = Serialize.put p >> Serialize.put a get = Mass <$> Serialize.get <*> Serialize.get -instance Serialize a => SafeCopy (Mass a)+instance (Serialize a, Typeable a) => SafeCopy (Mass a) where+ -- safecopy-0.10.0 changed its default implementations for these methods.+ -- The implementations below are copied from the pre-0.10.0 defaults.+ errorTypeName _ = "<unknown type>"+ getCopy = contain Serialize.get+ putCopy = contain . Serialize.put +instance Eq1 Mass where+ liftEq eq (Mass p a) (Mass q b) = p == q && eq a b+ instance Hashable a => Hashable (Mass a)-instance Hashable1 Mass+instance Hashable1 Mass where+ liftHashWithSalt h s (Mass m x) = hashWithSalt s m `h` x instance Serial1 Mass where serializeWith f (Mass p a) = serialize p >> f a@@ -123,6 +135,8 @@ {-# INLINE basicUnsafeMove #-} basicUnsafeGrow (MV_Mass v) n = MV_Mass `liftM` M.basicUnsafeGrow v n {-# INLINE basicUnsafeGrow #-}+ basicInitialize (MV_Mass v) = M.basicInitialize v+ {-# INLINE basicInitialize #-} instance Unbox a => G.Vector U.Vector (Mass a) where basicUnsafeFreeze (MV_Mass v) = V_Mass `liftM` G.basicUnsafeFreeze v@@ -172,8 +186,10 @@ instance Monoid a => Monoid (Mass a) where mempty = Mass 1 mempty {-# INLINE mempty #-}+#if !(MIN_VERSION_base(4,11,0)) mappend (Mass p a) (Mass q b) = Mass (p * q) (mappend a b) {-# INLINE mappend #-}+#endif instance Semigroup a => Semigroup (Mass a) where Mass p a <> Mass q b = Mass (p * q) (a <> b)@@ -185,7 +201,7 @@ {-# INLINE (>>-) #-} instance Monad Mass where- return = Mass 1+ return = pure {-# INLINE return #-} Mass p a >>= f = case f a of Mass q b -> Mass (p * q) b
src/Data/Approximate/Numerics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE ForeignFunctionInterface #-} -------------------------------------------------------------------- -- |@@ -62,7 +63,11 @@ -- -- 'flog' had better outperform it! It is provided merely for comparison. blog :: Floating a => a -> a-blog x = 6 * (x - 1) / (x + 1 + 4 * sqrt x);+blog x = 6 * (x - 1) / (x + 1 + 4 * sqrt x)+ -- 6 / (x + 1 + 4 * sqrt x) / (x-1) -- herbie's suggested replacement.+#ifdef HERBIE+{-# ANN blog "NoHerbie" #-}+#endif foreign import ccall unsafe pow_fast_lb :: Double -> Double -> Double foreign import ccall unsafe pow_fast_ub :: Double -> Double -> Double
src/Data/Approximate/Type.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TemplateHaskell #-}@@ -32,19 +30,18 @@ import Data.Bytes.Serial as Bytes import Data.Copointed import Data.Data-#if __GLASGOW_HASKELL__ < 710-import Data.Foldable-#endif import Data.Functor.Apply-import Data.Hashable-import Data.Hashable.Extras+import Data.Functor.Classes+import Data.Hashable (Hashable(..))+import Data.Hashable.Lifted (Hashable1(..)) import Data.Monoid import Data.Pointed import Data.SafeCopy import Data.Serialize as Serialize-import Data.Vector.Generic as G-import Data.Vector.Generic.Mutable as M-import Data.Vector.Unboxed as U+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Generic.Mutable as M+import qualified Data.Vector.Unboxed as U+import Data.Vector.Unboxed (Unbox) import GHC.Generics import Numeric.Log @@ -54,7 +51,7 @@ data Approximate a = Approximate { _confidence :: {-# UNPACK #-} !(Log Double) , _lo, _estimate, _hi :: a- } deriving (Eq,Show,Read,Typeable,Data,Generic)+ } deriving (Eq,Show,Read,Data,Generic) makeClassy ''Approximate @@ -66,10 +63,21 @@ put (Approximate p l m h) = Serialize.put p >> Serialize.put l >> Serialize.put m >> Serialize.put h get = Approximate <$> Serialize.get <*> Serialize.get <*> Serialize.get <*> Serialize.get -instance Serialize a => SafeCopy (Approximate a)+instance (Serialize a, Typeable a) => SafeCopy (Approximate a) where+ -- safecopy-0.10.0 changed its default implementations for these methods.+ -- The implementations below are copied from the pre-0.10.0 defaults.+ errorTypeName _ = "<unknown type>"+ getCopy = contain Serialize.get+ putCopy = contain . Serialize.put +instance Eq1 Approximate where+ liftEq eq (Approximate p la ma ha) (Approximate q lb mb hb) =+ p == q && eq la lb && eq ma mb && eq ha hb+ instance Hashable a => Hashable (Approximate a)-instance Hashable1 Approximate+instance Hashable1 Approximate where+ liftHashWithSalt h s (Approximate c low est high) =+ hashWithSalt s c `h` low `h` est `h` high instance Serial a => Serial (Approximate a) @@ -110,6 +118,8 @@ {-# INLINE basicUnsafeMove #-} basicUnsafeGrow (MV_Approximate v) n = MV_Approximate `liftM` M.basicUnsafeGrow v n {-# INLINE basicUnsafeGrow #-}+ basicInitialize (MV_Approximate v) = M.basicInitialize v+ {-# INLINE basicInitialize #-} instance Unbox a => G.Vector U.Vector (Approximate a) where basicUnsafeFreeze (MV_Approximate v) = V_Approximate `liftM` G.basicUnsafeFreeze v@@ -133,7 +143,7 @@ {-# INLINE elemseq #-} instance NFData a => NFData (Approximate a) where- rnf (Approximate _ l m h) = rnf l `seq` rnf m `seq` rnf h `seq` ()+ rnf (Approximate _ l m h) = rnf l `seq` rnf m `seq` rnf h instance Functor Approximate where fmap f (Approximate p l m h) = Approximate p (f l) (f m) (f h)
− tests/doctests.hsc
@@ -1,74 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE ForeignFunctionInterface #-}--------------------------------------------------------------------------------- |--- Module : Main (doctests)--- Copyright : (C) 2012-13 Edward Kmett--- License : BSD-style (see the file LICENSE)--- Maintainer : Edward Kmett <ekmett@gmail.com>--- Stability : provisional--- Portability : portable------ This module provides doctests for a project based on the actual versions--- of the packages it was built with. It requires a corresponding Setup.lhs--- to be added to the project-------------------------------------------------------------------------------module Main where--import Build_doctests (deps)-import Control.Applicative-import Control.Monad-import Data.List-import System.Directory-import System.FilePath-import Test.DocTest--##if defined(mingw32_HOST_OS)-##if defined(i386_HOST_ARCH)-##define USE_CP-import Control.Applicative-import Control.Exception-import Foreign.C.Types-foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool-foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt-##elif defined(x86_64_HOST_ARCH)-##define USE_CP-import Control.Applicative-import Control.Exception-import Foreign.C.Types-foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool-foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt-##endif-##endif---- | Run in a modified codepage where we can print UTF-8 values on Windows.-withUnicode :: IO a -> IO a-##ifdef USE_CP-withUnicode m = do- cp <- c_GetConsoleCP- (c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp-##else-withUnicode m = m-##endif--main :: IO ()-main = withUnicode $ getSources >>= \sources -> doctest $- "-isrc"- : "-idist/build/autogen"- : "-optP-include"- : "-optPdist/build/autogen/cabal_macros.h"- : "-hide-all-packages"- : "-Iincludes"- : map ("-package="++) deps ++ sources--getSources :: IO [FilePath]-getSources = filter (isSuffixOf ".hs") <$> go "src"- where- go dir = do- (dirs, files) <- getFilesAndDirectories dir- (files ++) . concat <$> mapM go dirs--getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])-getFilesAndDirectories dir = do- c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir- (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c
− travis/cabal-apt-install
@@ -1,27 +0,0 @@-#! /bin/bash-set -eu--APT="sudo apt-get -q -y"-CABAL_INSTALL_DEPS="cabal install --only-dependencies --force-reinstall"--$APT update-$APT install dctrl-tools--# Find potential system packages to satisfy cabal dependencies-deps()-{- local M='^\([^ ]\+\)-[0-9.]\+ (.*$'- local G=' -o ( -FPackage -X libghc-\L\1\E-dev )'- local E="$($CABAL_INSTALL_DEPS "$@" --dry-run -v 2> /dev/null \- | sed -ne "s/$M/$G/p" | sort -u)"- grep-aptavail -n -sPackage \( -FNone -X None \) $E | sort -u-}--$APT install $(deps "$@") libghc-quickcheck2-dev # QuickCheck is special-$CABAL_INSTALL_DEPS "$@" # Install the rest via Hackage--if ! $APT install hlint ; then- $APT install $(deps hlint)- cabal install hlint-fi-
− travis/config
@@ -1,16 +0,0 @@--- This provides a custom ~/.cabal/config file for use when hackage is down that should work on unix------ This is particularly useful for travis-ci to get it to stop complaining--- about a broken build when everything is still correct on our end.------ This uses Luite Stegeman's mirror of hackage provided by his 'hdiff' site instead------ To enable this, uncomment the before_script in .travis.yml--remote-repo: hdiff.luite.com:http://hdiff.luite.com/packages/archive-remote-repo-cache: ~/.cabal/packages-world-file: ~/.cabal/world-build-summary: ~/.cabal/logs/build.log-remote-build-reporting: anonymous-install-dirs user-install-dirs global