smallcheck 1.1.4 → 1.1.5
raw patch · 3 files changed
+39/−4 lines, 3 filesdep ~logictdep ~mtl
Dependency ranges changed: logict, mtl
Files
- CHANGELOG.md +9/−0
- Test/SmallCheck/Series.hs +29/−3
- smallcheck.cabal +1/−1
CHANGELOG.md view
@@ -1,6 +1,15 @@ Changes ======= +Version 1.1.5+-------------++* Add `limit :: Monad m => Int -> Series m a -> Series m a`+* Add `genericSeries` and `genericCoseries`, so that you can use the generic+ implementations more flexibly. Previously, the generic implementation was+ only avaialable as the default method for `series`/`coseries` but not as+ standalone functions.+ Version 1.1.4 -------------
Test/SmallCheck/Series.hs view
@@ -24,7 +24,7 @@ -------------------------------------------------------------------- {-# LANGUAGE CPP, RankNTypes, MultiParamTypeClasses, FlexibleInstances,- GeneralizedNewtypeDeriving, FlexibleContexts #-}+ GeneralizedNewtypeDeriving, FlexibleContexts, ScopedTypeVariables #-} -- The following is needed for generic instances {-# LANGUAGE DefaultSignatures, FlexibleContexts, TypeOperators, TypeSynonymInstances, FlexibleInstances, OverlappingInstances #-}@@ -165,6 +165,10 @@ -- * Basic definitions Depth, Series, Serial(..), CoSerial(..), + -- * Generic implementations+ genericSeries,+ genericCoseries,+ -- * Convenient wrappers Positive(..), NonNegative(..), NonEmpty(..), @@ -174,6 +178,7 @@ decDepth, getDepth, generate,+ limit, listSeries, list, listM,@@ -204,8 +209,13 @@ series :: Series m a default series :: (Generic a, GSerial m (Rep a)) => Series m a- series = to <$> gSeries+ series = genericSeries +genericSeries+ :: (Monad m, Generic a, GSerial m (Rep a))+ => Series m a+genericSeries = to <$> gSeries+ class Monad m => CoSerial m a where -- | A proper 'coseries' implementation should pass the depth unchanged to -- its first argument. Doing otherwise will make enumeration of curried@@ -213,8 +223,12 @@ coseries :: Series m b -> Series m (a->b) default coseries :: (Generic a, GCoSerial m (Rep a)) => Series m b -> Series m (a->b)- coseries rs = (. from) <$> gCoseries rs+ coseries = genericCoseries +genericCoseries+ :: (Monad m, Generic a, GCoSerial m (Rep a))+ => Series m b -> Series m (a->b)+genericCoseries rs = (. from) <$> gCoseries rs -- }}} ------------------------------@@ -228,6 +242,18 @@ generate f = do d <- getDepth msum $ map return $ f d++-- | Limit a 'Series' to its first @n@ elements+limit :: forall m a . Monad m => Int -> Series m a -> Series m a+limit n0 (Series s) = Series $ go n0 s+ where+ go :: MonadLogic ml => Int -> ml b -> ml b+ go 0 _ = mzero+ go n mb1 = do+ cons :: Maybe (b, ml b) <- msplit mb1+ case cons of+ Nothing -> mzero+ Just (b, mb2) -> return b `mplus` go (n-1) mb2 suchThat :: Series m a -> (a -> Bool) -> Series m a suchThat s p = s >>= \x -> if p x then pure x else empty
smallcheck.cabal view
@@ -1,5 +1,5 @@ Name: smallcheck-Version: 1.1.4+Version: 1.1.5 Cabal-Version: >= 1.6 License: BSD3 License-File: LICENSE