Skip to content

Commit 7ea4db7

Browse files
committed
add Scientific instances for ghc
mhs can't build `binary-0.8.9.3`, which is a dependency
1 parent d6e2a40 commit 7ea4db7

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

QuickCheck.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ library
147147
-DNO_DATAFIX
148148
-DNO_HASHABLE
149149
-DNO_OLDTIME
150+
-DNO_SCIENTIFIC
150151

151152
-- random is explicitly Trustworthy since 1.0.1.0
152153
-- similar constraint for containers
@@ -158,6 +159,7 @@ library
158159
, integer-logarithms >=1.0.3.1 && <1.1
159160
, hashable >=1.4.4.0 && <1.6
160161
, old-time >=1.1.0.0 && <1.2
162+
, scientific >=0.3.8.0 && <0.4
161163

162164
if impl(ghc >= 9.8)
163165
ghc-options: -Wno-x-partial

src/Test/QuickCheck/Arbitrary.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ import Data.Hashable (Hashable, hashed, hashedHash, Hashed)
213213
#ifndef NO_OLDTIME
214214
import qualified System.Time as OldTime
215215
#endif
216+
#ifndef NO_SCIENTIFIC
217+
import qualified Data.Scientific as Scientific
218+
#endif
216219
#ifndef NO_SEMIGROUP
217220
import qualified Data.Semigroup as Semigroup
218221
#endif
@@ -265,6 +268,7 @@ a Integer, Natural
265268
a Int($ -> 64)
266269
a Word($ -> 64)
267270
a Char, Float, Double
271+
if scientific allowed: ac Scientific
268272
a CChar, CSChar, CUChar, CShort, CUShort, CInt, CUInt, CLong, CULong, CPtrdiff, CSize, CWchar, CSigAtomic, CLLong, CULLong, CIntPtr, CUIntPtr, CIntMax, CUIntMax
269273
if c type constructors allowed: a CClock, CTime
270274
if foreign c unsigned seconds: a CUSeconds, CSUSeconds
@@ -924,6 +928,16 @@ instance Arbitrary Double where
924928

925929
shrink = shrinkDecimal
926930

931+
#ifndef NO_SCIENTIFIC
932+
instance Arbitrary Scientific.Scientific where
933+
arbitrary = liftA2 Scientific.scientific arbitrary arbitrary
934+
shrink s = map (uncurry Scientific.scientific) $
935+
shrink (Scientific.coefficient s, Scientific.base10Exponent s)
936+
937+
instance CoArbitrary Scientific.Scientific where
938+
coarbitrary s = coarbitrary (Scientific.coefficient s, Scientific.base10Exponent s)
939+
#endif
940+
927941
instance Arbitrary CChar where
928942
arbitrary = arbitrarySizedBoundedIntegral
929943
shrink = shrinkIntegral

src/Test/QuickCheck/Function.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ import Data.Fixed
124124
import GHC.Generics hiding (C)
125125
#endif
126126

127+
#ifndef NO_SCIENTIFIC
128+
import qualified Data.Scientific as Scientific
129+
#endif
130+
127131
import Test.QuickCheck.Compat
128132

129133
--------------------------------------------------------------------------
@@ -361,6 +365,13 @@ instance Function Double where
361365
instance Function Natural where
362366
function = functionIntegral
363367

368+
#ifndef NO_SCIENTIFIC
369+
instance Function Scientific.Scientific where
370+
function = functionMap
371+
(\s -> (Scientific.coefficient s, Scientific.base10Exponent s))
372+
(uncurry Scientific.scientific)
373+
#endif
374+
364375
-- instances for assorted types in the base package
365376

366377
instance Function Ordering where

0 commit comments

Comments
 (0)