Community
Modules 18

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:














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.

data 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.

Fun :: (a :-> b, b, Shrunk) -> (a -> b) -> Fun a b

mkFun :: (a :-> b) -> b -> Fun a b

Create a `Fun` from a function representation and a default value (in case the function is partial).

applyFun :: 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"

apply :: Fun a b -> (a -> b)

Alias to applyFun.

applyFun2 :: 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]

applyFun3 :: Fun (a, b, c) d -> (a -> b -> c -> d)

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

data a :-> c

The type of possibly partial concrete functions

class Function a

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.

functionMap :: Function b => (a -> b) -> (b -> a) -> (a -> c) -> (a :-> c)

The basic building block for Function instances. Provides a Function instance by mapping to and from a type that already has a Function instance.

functionShow :: (Show a, Read a) => (a -> c) -> (a :-> c)

Provides a Function instance for types with Show and Read.

functionIntegral :: Integral a => (a -> b) -> (a :-> b)

Provides a Function instance for types with Integral.

functionRealFrac :: RealFrac a => (a -> b) -> (a :-> b)

Provides a Function instance for types with RealFrac.

functionBoundedEnum :: (Eq a, Bounded a, Enum a) => (a -> b) -> (a :-> b)

Provides a Function instance for types with Bounded and Enum. Use only for small types (i.e. not integers): creates the list [minBound..maxBound]!

functionElements :: Eq a => [a] -> (a -> b) -> (a :-> b)

Provides a Function instance for small finite types.

functionVoid :: (forall b. void -> b) -> void :-> c

Provides a Function instance for types isomorphic to Void.

An actual Function Void instance is defined in quickcheck-instances.

functionMapWith :: ((b -> c) -> (b :-> c)) -> (a -> b) -> (b -> a) -> (a -> c) -> (a :-> c)

functionEitherWith :: ((a -> c) -> (a :-> c)) -> ((b -> c) -> (b :-> c)) -> (Either a b -> c) -> (Either a b :-> c)

functionPairWith :: ((a -> b -> c) -> (a :-> (b -> c))) -> ((b -> c) -> (b :-> c)) -> ((a, b) -> c) -> ((a, b) :-> c)

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"

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]

Fn3 :: (a -> b -> c -> d) -> Fun (a, b, c) d

A modifier for testing ternary functions.

Instances

91
  • instance Functor ((:->) a)
  • instance (Show a, Show b) => Show (a :-> b)
  • instance Function ()
  • instance Function a => Function (Const a b)
  • instance Function a => Function (Identity a)
  • instance (Function a, Function b) => Function (a, b)
  • instance (Function a, Function b) => Function (Either a b)
  • instance (Function a, Function b, Function c) => Function (a, b, c)
  • instance (Function a, Function b, Function c, Function d) => Function (a, b, c, d)
  • instance (Function a, Function b, Function c, Function d, Function e) => Function (a, b, c, d, e)
  • instance (Function a, Function b, Function c, Function d, Function e, Function f) => Function (a, b, c, d, e, f)
  • instance (Function a, Function b, Function c, Function d, Function e, Function f, Function g) => Function (a, b, c, d, e, f, g)
  • instance Function a => Function [a]
  • instance Function a => Function (NonEmpty.NonEmpty a)
  • instance Function a => Function (ZipList a)
  • instance Function a => Function (Maybe a)
  • instance Function Bool
  • instance Function Integer
  • instance Function Int
  • instance Function Word
  • instance Function Char
  • instance Function Float
  • instance Function Double
  • instance Function Natural
  • instance Function Ordering
  • instance (Integral a, Function a) => Function (Ratio a)
  • instance HasResolution a => Function (Fixed a)
  • instance (RealFloat a, Function a) => Function (Complex a)
  • instance (Ord a, Function a) => Function (Set.Set a)
  • instance (Ord a, Function a, Function b) => Function (Map.Map a b)
  • instance Function IntSet.IntSet
  • instance Function a => Function (IntMap.IntMap a)
  • instance Function a => Function (Sequence.Seq a)
  • instance Function a => Function (Tree.Tree a)
  • instance Function Int8
  • instance Function Int16
  • instance Function Int32
  • instance Function Int64
  • instance Function Word8
  • instance Function Word16
  • instance Function Word32
  • instance Function Word64
  • instance Function Newline
  • instance Function NewlineMode
  • instance Function a => Function (Monoid.Dual a)
  • instance Function Monoid.All
  • instance Function Monoid.Any
  • instance Function a => Function (Monoid.Sum a)
  • instance Function a => Function (Monoid.Product a)
  • instance Function a => Function (Monoid.First a)
  • instance Function a => Function (Monoid.Last a)
  • instance Function (f a) => Function (Monoid.Alt f a)
  • instance Function a => Function (Semigroup.Min a)
  • instance Function a => Function (Semigroup.Max a)
  • instance Function a => Function (Semigroup.Last a)
  • instance Function a => Function (Semigroup.First a)
  • instance Function a => Function (Semigroup.WrappedMonoid a)
  • instance (Function a, Function b) => Function (Semigroup.Arg a b)
  • instance Function a => Function (Bits.And a)
  • instance Function a => Function (Bits.Ior a)
  • instance Function a => Function (Bits.Xor a)
  • instance Function a => Function (Bits.Iff a)
  • instance Function FormatSign
  • instance Function FormatAdjustment
  • instance Function FormatParse
  • instance Function FieldFormat
  • instance Function GeneralCategory
  • instance Function SeekMode
  • instance Function IOMode
  • instance Function BufferMode
  • instance Function ExitCode
  • instance Function Version
  • instance Function ByteArray
  • instance Function a => Function (Solo a)
  • instance Function a => Function (Down a)
  • instance Function A
  • instance Function B
  • instance Function C
  • instance Function OrdA
  • instance Function OrdB
  • instance Function OrdC
  • instance (Function a, CoArbitrary a, Arbitrary b) => Arbitrary (a :-> b)
  • instance GFunction U1
  • instance (GFunction f, GFunction g) => GFunction (f :*: g)
  • instance (GFunction f, GFunction g) => GFunction (f :+: g)
  • instance GFunction f => GFunction (M1 i c f)
  • instance Function a => GFunction (K1 i a)
  • instance Eq Shrunk
  • instance Functor (Fun a)
  • instance (Show a, Show b) => Show (Fun a b)
  • instance (Function a, CoArbitrary a, Arbitrary b) => Arbitrary (Fun a b)
Build record and source files

Community contribution. The service has not verified this documentation. The generator reported 30 diagnostics.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-aa6debbd-web-3

Metadata snapshot: f17ab6aeb2a7b6daf9fba7614097e138beeef85fa92c3fb7fdfed9ed0e49728c

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.