hedgehog-fn 1.0 → 1.1
raw patch · 4 files changed
+66/−31 lines, 4 filesdep ~contravariantdep ~hedgehogdep ~transformersnew-uploaderPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: contravariant, hedgehog, transformers
API changes (from Hackage documentation)
- Hedgehog.Function.Internal: instance Hedgehog.Function.Internal.Arg Data.Void.Void
- Hedgehog.Function.Internal: instance Hedgehog.Function.Internal.Arg GHC.Integer.Type.Integer
- Hedgehog.Function.Internal: instance Hedgehog.Function.Internal.Vary Data.Void.Void
- Hedgehog.Function.Internal: instance Hedgehog.Function.Internal.Vary GHC.Integer.Type.Integer
+ Hedgehog.Function: ($dmbuild) :: (Arg a, Generic a, GArg (Rep a)) => (a -> c) -> a :-> c
+ Hedgehog.Function: ($dmvary) :: forall (m :: Type -> Type). (Vary a, Generic a, GVary (Rep a)) => CoGenT m a
+ Hedgehog.Function.Internal: ($dmbuild) :: (Arg a, Generic a, GArg (Rep a)) => (a -> c) -> a :-> c
+ Hedgehog.Function.Internal: ($dmvary) :: forall (m :: Type -> Type). (Vary a, Generic a, GVary (Rep a)) => CoGenT m a
+ Hedgehog.Function.Internal: instance Hedgehog.Function.Internal.Arg GHC.Base.Void
+ Hedgehog.Function.Internal: instance Hedgehog.Function.Internal.Arg GHC.Num.Integer.Integer
+ Hedgehog.Function.Internal: instance Hedgehog.Function.Internal.Vary GHC.Base.Void
+ Hedgehog.Function.Internal: instance Hedgehog.Function.Internal.Vary GHC.Num.Integer.Integer
- Hedgehog.Function: build :: (Arg a, Generic a, GArg (Rep a)) => (a -> c) -> a :-> c
+ Hedgehog.Function: build :: Arg a => (a -> c) -> a :-> c
- Hedgehog.Function: data CoGenT m a
+ Hedgehog.Function: data CoGenT (m :: Type -> Type) a
- Hedgehog.Function: forAllFn :: (Show a, Show b, Monad m) => Gen (Fn a b) -> PropertyT m (a -> b)
+ Hedgehog.Function: forAllFn :: forall a b (m :: Type -> Type). (Show a, Show b, Monad m) => Gen (Fn a b) -> PropertyT m (a -> b)
- Hedgehog.Function: gvary :: (Generic a, GVary (Rep a)) => CoGenT m a
+ Hedgehog.Function: gvary :: forall a (m :: Type -> Type). (Generic a, GVary (Rep a)) => CoGenT m a
- Hedgehog.Function: vary :: (Vary a, Generic a, GVary (Rep a)) => CoGenT m a
+ Hedgehog.Function: vary :: forall (m :: Type -> Type). Vary a => CoGenT m a
- Hedgehog.Function: varyIntegral :: Integral a => CoGenT m a
+ Hedgehog.Function: varyIntegral :: forall a (m :: Type -> Type). Integral a => CoGenT m a
- Hedgehog.Function.Internal: CoGenT :: (forall b. a -> GenT m b -> GenT m b) -> CoGenT m a
+ Hedgehog.Function.Internal: CoGenT :: (forall b. () => a -> GenT m b -> GenT m b) -> CoGenT (m :: Type -> Type) a
- Hedgehog.Function.Internal: [Map] :: (a -> b) -> (b -> a) -> (b :-> c) -> a :-> c
+ Hedgehog.Function.Internal: [Map] :: forall a b c. (a -> b) -> (b -> a) -> (b :-> c) -> a :-> c
- Hedgehog.Function.Internal: [Nil] :: a :-> c
+ Hedgehog.Function.Internal: [Nil] :: forall a c. a :-> c
- Hedgehog.Function.Internal: [Pair] :: (a :-> (b :-> c)) -> (a, b) :-> c
+ Hedgehog.Function.Internal: [Pair] :: forall a1 b c. (a1 :-> (b :-> c)) -> (a1, b) :-> c
- Hedgehog.Function.Internal: [Sum] :: (a :-> c) -> (b :-> c) -> Either a b :-> c
+ Hedgehog.Function.Internal: [Sum] :: forall a1 c b. (a1 :-> c) -> (b :-> c) -> Either a1 b :-> c
- Hedgehog.Function.Internal: [Unit] :: c -> () :-> c
+ Hedgehog.Function.Internal: [Unit] :: forall c. c -> () :-> c
- Hedgehog.Function.Internal: [applyCoGenT] :: CoGenT m a -> forall b. a -> GenT m b -> GenT m b
+ Hedgehog.Function.Internal: [applyCoGenT] :: CoGenT (m :: Type -> Type) a -> forall b. () => a -> GenT m b -> GenT m b
- Hedgehog.Function.Internal: build :: (Arg a, Generic a, GArg (Rep a)) => (a -> c) -> a :-> c
+ Hedgehog.Function.Internal: build :: Arg a => (a -> c) -> a :-> c
- Hedgehog.Function.Internal: class GArg a
+ Hedgehog.Function.Internal: class GArg (a :: Type -> Type)
- Hedgehog.Function.Internal: class GVary a
+ Hedgehog.Function.Internal: class GVary (a :: Type -> Type)
- Hedgehog.Function.Internal: forAllFn :: (Show a, Show b, Monad m) => Gen (Fn a b) -> PropertyT m (a -> b)
+ Hedgehog.Function.Internal: forAllFn :: forall a b (m :: Type -> Type). (Show a, Show b, Monad m) => Gen (Fn a b) -> PropertyT m (a -> b)
- Hedgehog.Function.Internal: gvary :: (Generic a, GVary (Rep a)) => CoGenT m a
+ Hedgehog.Function.Internal: gvary :: forall a (m :: Type -> Type). (Generic a, GVary (Rep a)) => CoGenT m a
- Hedgehog.Function.Internal: gvary' :: GVary a => CoGenT m (a x)
+ Hedgehog.Function.Internal: gvary' :: forall (m :: Type -> Type) x. GVary a => CoGenT m (a x)
- Hedgehog.Function.Internal: newtype CoGenT m a
+ Hedgehog.Function.Internal: newtype CoGenT (m :: Type -> Type) a
- Hedgehog.Function.Internal: variant :: Word64 -> GenT m b -> GenT m b
+ Hedgehog.Function.Internal: variant :: forall (m :: Type -> Type) b. Word64 -> GenT m b -> GenT m b
- Hedgehog.Function.Internal: variant' :: Word64 -> CoGenT m b -> CoGenT m b
+ Hedgehog.Function.Internal: variant' :: forall (m :: Type -> Type) b. Word64 -> CoGenT m b -> CoGenT m b
- Hedgehog.Function.Internal: vary :: (Vary a, Generic a, GVary (Rep a)) => CoGenT m a
+ Hedgehog.Function.Internal: vary :: forall (m :: Type -> Type). Vary a => CoGenT m a
- Hedgehog.Function.Internal: varyIntegral :: Integral a => CoGenT m a
+ Hedgehog.Function.Internal: varyIntegral :: forall a (m :: Type -> Type). Integral a => CoGenT m a
Files
- ChangeLog.md +7/−0
- example/Example.hs +39/−20
- hedgehog-fn.cabal +7/−7
- src/Hedgehog/Function/Internal.hs +13/−4
ChangeLog.md view
@@ -1,3 +1,10 @@+1.1 - 2026-07-22++* Upgrade hedgehog to 1.7, supporting hedgehog 1.0-1.8+* Upgrade contravariant to support versions up to 1.6+* Upgrade transformers to support versions up to 0.7+* Add support for GHC 9.0.2, 9.2.8, 9.4.8, 9.6.7, 9.8.4, 9.10.3, 9.12.4+ 1.0 - 2019-05-17 * Drop support for GHC < 8
example/Example.hs view
@@ -1,32 +1,51 @@-{-# language ScopedTypeVariables #-}-{-# language TemplateHaskell #-}-{-# language TypeApplications #-}-{-# language RankNTypes #-}-module Main where+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeApplications #-} -import Hedgehog-import qualified Hedgehog.Gen as Gen-import qualified Hedgehog.Range as Range+module Main where -import Hedgehog.Function+import Hedgehog+import qualified Hedgehog.Gen as Gen+import qualified Hedgehog.Range as Range+import Hedgehog.Function -fun_idempotent+funIdempotent :: forall m a . (Monad m, Arg a, Vary a, Eq a, Show a) => Gen a -> PropertyT m ()-fun_idempotent ga = do- a <- forAll ga- f <- fmap apply . forAll $ fn @a ga+funIdempotent genA = do+ a <- forAll genA+ f <- forAllFn $ fn @a genA f a === f (f a) -prop_unit_fun_idempotent :: Property-prop_unit_fun_idempotent =+prop_unit_funIdempotent :: Property+prop_unit_funIdempotent = property $- fun_idempotent $ Gen.choice [Right <$> Gen.bool :: Gen (Either () Bool)]+ funIdempotent $ Gen.choice [Right <$> Gen.bool :: Gen (Either () Bool)] +funCongEquality+ :: forall m a+ . (Monad m, Arg a, Vary a, Eq a, Show a)+ => Gen a+ -> Gen a+ -> PropertyT m ()+funCongEquality genA genB = do+ a <- forAll genA+ b <- forAll genB+ f <- forAllFn $ fn @a genA+ if a == b+ then f a === f b+ else pure ()++prop_funCongEquality :: Property+prop_funCongEquality =+ property $+ funCongEquality (Gen.int (Range.linear 1 10)) (Gen.int (Range.linear 1 10))+ -- | map (f . g) xs = map f (map g xs)-map_compose+mapCompose :: forall f a b c . ( Functor f , Show (f a)@@ -41,7 +60,7 @@ -> Gen b -> Gen c -> Property-map_compose genF genA genB genC =+mapCompose genF genA genB genC = property $ do g <- forAllFn $ fn @a genB f <- forAllFn $ fn @b genC@@ -50,11 +69,11 @@ prop_map_list :: Property prop_map_list =- map_compose+ mapCompose (Gen.list (Range.constant 0 100)) Gen.bool Gen.bool Gen.bool main :: IO Bool-main = checkParallel $$(discover)+main = checkParallel $$discover
hedgehog-fn.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: hedgehog-fn-version: 1.0+version: 1.1 synopsis: Function generation for `hedgehog` description: Generating shrinkable, showable functions with `hedgehog`. See `Hedgehog.Function` for example usages.@@ -17,7 +17,7 @@ build-type: Simple cabal-version: >=1.10 extra-source-files: ChangeLog.md-tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.3, GHC==8.6.5+tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.3, GHC==8.6.5, GHC==8.8.4, GHC==8.10.7, GHC==9.0.2, GHC==9.2.8, GHC==9.4.8, GHC==9.6.7, GHC==9.8.4, GHC==9.10.3, GHC==9.12.4 source-repository head type: git@@ -31,9 +31,9 @@ exposed-modules: Hedgehog.Function , Hedgehog.Function.Internal build-depends: base >=4.8 && <5- , contravariant >=1.4 && <1.6- , hedgehog >=1.0 && <1.1- , transformers >=0.5 && <0.6+ , contravariant >=1.4 && <1.7+ , hedgehog >=1.0 && <1.9+ , transformers >=0.4.2 && <0.8 hs-source-dirs: src default-language: Haskell2010 @@ -44,7 +44,7 @@ else buildable: False hs-source-dirs: example- build-depends: base >=4.8 && <5- , hedgehog >=1.0 && <1.1+ build-depends: base+ , hedgehog , hedgehog-fn default-language: Haskell2010
src/Hedgehog/Function/Internal.hs view
@@ -169,8 +169,15 @@ unsafeApply f = fromJust . apply' f -- | The type of randomly-generated functions+{-+The lone 'b' here is important; we need is as a fall-through case so that we+can have finitely-sized showable functions. If we didn't have it, then we'd+never be able to render functions that have an infinitely-sized argument+(like functions on Integers).+-} data Fn a b = Fn b (a :-> TreeT (MaybeT Identity) b) + -- | Extract the root value from a 'TreeT'. Unsafe. unsafeFromTree :: Functor m => TreeT (MaybeT m) a -> m a unsafeFromTree =@@ -180,15 +187,17 @@ instance (Show a, Show b) => Show (Fn a b) where show (Fn b a) =+ "\\case\n" ++ case table a of- [] -> "_ -> " ++ show b- ta -> showTable ta ++ "_ -> " ++ show b+ [] -> " _ -> " ++ show b+ ta -> showTable ta ++ " _ -> " ++ show b where showTable :: (Show a, Show b) => [(a, TreeT (MaybeT Identity) b)] -> String- showTable [] = "<empty function>\n"+ showTable [] = " <empty function>\n" showTable (x : xs) = unlines (showCase <$> x : xs) where- showCase (lhs, rhs) = show lhs ++ " -> " ++ show (runIdentity $ unsafeFromTree rhs)+ showCase (lhs, rhs) =+ " " ++ show lhs ++ " -> " ++ show (runIdentity $ unsafeFromTree rhs) -- | Shrink the function shrinkFn :: (b -> [b]) -> a :-> b -> [a :-> b]