data Fun a b
Generation of random shrinkable, showable functions.
To generate random values of type ,
you must have an instance Fun a b.Function a
See also applyFun, and Fn with GHC >= 7.8.
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 ,
you must have an instance Fun a b.
If your type has a Function aShow 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 instance for an example of the latter.Function [a]
data Fun a bGeneration of random shrinkable, showable functions.
To generate random values of type ,
you must have an instance Fun a b.Function a
See also applyFun, and Fn with GHC >= 7.8.
Fun :: (a :-> b, b, Shrunk) -> (a -> b) -> Fun a bmkFun :: (a :-> b) -> b -> Fun a bCreate 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 :-> cThe type of possibly partial concrete functions
class Function aThe 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.
function :: (a -> b) -> (a :-> b)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 :-> cProvides a Function instance for types isomorphic to Void.
An actual instance is defined in
Function Voidquickcheck-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 bA 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) cA 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) dA modifier for testing ternary functions.
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 Boolinstance Function Integerinstance Function Intinstance Function Wordinstance Function Charinstance Function Floatinstance Function Doubleinstance Function Naturalinstance Function Orderinginstance (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.IntSetinstance Function a => Function (IntMap.IntMap a)instance Function a => Function (Sequence.Seq a)instance Function a => Function (Tree.Tree a)instance Function Int8instance Function Int16instance Function Int32instance Function Int64instance Function Word8instance Function Word16instance Function Word32instance Function Word64instance Function Newlineinstance Function NewlineModeinstance Function a => Function (Monoid.Dual a)instance Function Monoid.Allinstance Function Monoid.Anyinstance 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 FormatSigninstance Function FormatAdjustmentinstance Function FormatParseinstance Function FieldFormatinstance Function GeneralCategoryinstance Function SeekModeinstance Function IOModeinstance Function BufferModeinstance Function ExitCodeinstance Function Versioninstance Function ByteArrayinstance Function a => Function (Solo a)instance Function a => Function (Down a)instance Function Ainstance Function Binstance Function Cinstance Function OrdAinstance Function OrdBinstance Function OrdCinstance (Function a, CoArbitrary a, Arbitrary b) => Arbitrary (a :-> b)instance GFunction U1instance (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 Shrunkinstance Functor (Fun a)instance (Show a, Show b) => Show (Fun a b)instance (Function a, CoArbitrary a, Arbitrary b) => Arbitrary (Fun a b)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