HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

ModuleQuickCheck-2.15.0.1Haskell2010

Test.QuickCheck.Function

Generation of random shrinkable, showable functions. See the paper "Shrinking and showing functions" by Koen Claessen.

Note: most of the contents of this module are re-exported by Test.QuickCheck. You probably do not need to import it directly.

Example of use:

Example5 expressions
:{let prop :: Fun String Integer -> Bool    prop (Fun _ f) = f "monkey" == f "banana" || f "banana" == f "elephant":}quickCheck prop*** Failed! Falsified (after 3 tests and 134 shrinks):{"elephant"->1, "monkey"->1, _->0}

To generate random values of type Fun a b, you must have an instance Function a. If your type has a Show instance, you can use functionShow to write the instance; otherwise, use functionMap to give a bijection between your type and a type that is already an instance of Function. See the Function [a] instance for an example of the latter.

  • 2 types
  • 1 class
  • 14 values
datadata Fun a b
#

Generation of random shrinkable, showable functions.

To generate random values of type Fun a b, you must have an instance Function a.

See also applyFun, and Fn with GHC >= 7.8.

Constructors

  • Fun (a :-> b, b, Shrunk) (a -> b)
Instances3Functor, Show, Arbitrary
valueapplyFun :: Fun a b -> a -> b
#

Extracts the value of a function.

Fn is the pattern equivalent of this function.

prop :: Fun String Integer -> Bool
prop f = applyFun f "banana" == applyFun f "monkey"
      || applyFun f "banana" == applyFun f "elephant"
valueapplyFun2 :: Fun (a, b) c -> a -> b -> c
#

Extracts the value of a binary function.

Fn2 is the pattern equivalent of this function.

prop_zipWith :: Fun (Int, Bool) Char -> [Int] -> [Bool] -> Bool
prop_zipWith f xs ys = zipWith (applyFun2 f) xs ys == [ applyFun2 f x y | (x, y) <- zip xs ys]
valueapplyFun3 :: Fun (a, b, c) d -> a -> b -> c -> d
#

Extracts the value of a ternary function. Fn3 is the pattern equivalent of this function.

datadata (:->) a c where
#

The type of possibly partial concrete functions

Instances3Functor, Show, Arbitrary
classclass Function a where
#

The class Function a is used for random generation of showable functions of type a -> b.

There is a default implementation for function, which you can use if your type has structural equality. Otherwise, you can normally use functionMap or functionShow.

Methods

Instances53Function, …
patternpattern Fn :: (a -> b) -> Fun a b
#

A modifier for testing functions.

prop :: Fun String Integer -> Bool
prop (Fn f) = f "banana" == f "monkey"
           || f "banana" == f "elephant"
patternpattern Fn2 :: (a -> b -> c) -> Fun (a, b) c
#

A modifier for testing binary functions.

prop_zipWith :: Fun (Int, Bool) Char -> [Int] -> [Bool] -> Bool
prop_zipWith (Fn2 f) xs ys = zipWith f xs ys == [ f x y | (x, y) <- zip xs ys]
patternpattern Fn3 :: (a -> b -> c -> d) -> Fun (a, b, c) d
#

A modifier for testing ternary functions.