Safe Haskell | None |
---|
This module provides functions for generating lists of samples
from a range of input values. This is primarily useful for
generating test cases. Ranges can be specified for types that are
members of the Interval
class. Each sampling procedure generates
a (finite or infinite) list of values from the range. We provide
sampling procedures for
- generating the range in its entirety (
sample_all
) - sampling every nth element from a range (
sample_step
) - generating a random sample from the range (
sample_random
)
Synopsis
- class Interval a where
- interval :: a -> a -> [a]
- class Zero a where
- zero :: a -> a
- class Random a
- sample_all :: Interval a => a -> a -> [a]
- sample_step :: (Integral a, Integral b, Interval c) => a -> b -> c -> c -> [c]
- sample_random :: (Random a, RandomGen g) => g -> a -> a -> [a]
- sample_all0 :: (Zero a, Interval a) => a -> [a]
- sample_step0 :: (Integral a, Integral b, Zero c, Interval c) => a -> b -> c -> [c]
- sample_random0 :: (Random a, Zero a, RandomGen g) => g -> a -> [a]
Interval class
class Interval a where Source #
The Interval
class contains types for which an interval of
values can be specified by giving a lower bound and an upper
bound. Intervals are specified as
, for
example: interval
min max
interval (0,0) (1,2) = [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)].
interval :: a -> a -> [a] Source #
Takes a range (min,max) and returns a list of all values with lower bound min and upper bound max.
Instances
Interval Bool # | |
Interval Double # | |
Interval Int # | |
Interval Integer # | |
Interval () # | |
Defined in Quipper.Utils.Sampling | |
Interval IntM # | |
Interval a => Interval [a] # | |
Defined in Quipper.Utils.Sampling | |
(Interval a, Interval b) => Interval (a, b) # | |
Defined in Quipper.Utils.Sampling | |
(Interval a, Interval b, Interval c) => Interval (a, b, c) # | |
Defined in Quipper.Utils.Sampling | |
(Interval a, Interval b, Interval c, Interval d) => Interval (a, b, c, d) # | |
Defined in Quipper.Utils.Sampling | |
(Interval a, Interval b, Interval c, Interval d, Interval e) => Interval (a, b, c, d, e) # | |
Defined in Quipper.Utils.Sampling | |
(Interval a, Interval b, Interval c, Interval d, Interval e, Interval f) => Interval (a, b, c, d, e, f) # | |
Defined in Quipper.Utils.Sampling | |
(Interval a, Interval b, Interval c, Interval d, Interval e, Interval f, Interval g) => Interval (a, b, c, d, e, f, g) # | |
Defined in Quipper.Utils.Sampling |
Zero class
Types in the Zero
class have an "origin", i.e., an element
that can conveniently serve as the starting point for intervals.
Inputs any element of the type and outputs the corresponding "zero" element, for example:
zero ([1,2],3,True) = ([0,0],0,False)
Instances
Zero Bool # | |
Zero Double # | |
Zero Int # | |
Zero Integer # | |
Zero () # | |
Defined in Quipper.Utils.Sampling | |
Zero IntM # | |
Zero a => Zero [a] # | |
Defined in Quipper.Utils.Sampling | |
(Zero a, Zero b) => Zero (a, b) # | |
Defined in Quipper.Utils.Sampling | |
(Zero a, Zero b, Zero c) => Zero (a, b, c) # | |
Defined in Quipper.Utils.Sampling | |
(Zero a, Zero b, Zero c, Zero d) => Zero (a, b, c, d) # | |
Defined in Quipper.Utils.Sampling | |
(Zero a, Zero b, Zero c, Zero d, Zero e) => Zero (a, b, c, d, e) # | |
Defined in Quipper.Utils.Sampling | |
(Zero a, Zero b, Zero c, Zero d, Zero e, Zero f) => Zero (a, b, c, d, e, f) # | |
Defined in Quipper.Utils.Sampling | |
(Zero a, Zero b, Zero c, Zero d, Zero e, Zero f, Zero g) => Zero (a, b, c, d, e, f, g) # | |
Defined in Quipper.Utils.Sampling |
Random class
We extend the class Random
with tuples and lists.
With a source of random number supply in hand, the Random
class allows the
programmer to extract random values of a variety of types.
Instances
Random Bool | |
Random Char | |
Random Double | |
Defined in System.Random | |
Random Float | |
Random Int | |
Random Int8 | |
Random Int16 | |
Random Int32 | |
Random Int64 | |
Random Integer | |
Defined in System.Random | |
Random Word | |
Random Word8 | |
Random Word16 | |
Defined in System.Random | |
Random Word32 | |
Defined in System.Random | |
Random Word64 | |
Defined in System.Random | |
Random () # | 0-tuples |
Random CChar | |
Random CSChar | |
Defined in System.Random | |
Random CUChar | |
Defined in System.Random | |
Random CShort | |
Defined in System.Random | |
Random CUShort | |
Defined in System.Random | |
Random CInt | |
Random CUInt | |
Random CLong | |
Random CULong | |
Defined in System.Random | |
Random CLLong | |
Defined in System.Random | |
Random CULLong | |
Defined in System.Random | |
Random CFloat | |
Defined in System.Random | |
Random CDouble | |
Defined in System.Random | |
Random CPtrdiff | |
Defined in System.Random | |
Random CSize | |
Random CWchar | |
Defined in System.Random | |
Random CSigAtomic | |
Defined in System.Random randomR :: RandomGen g => (CSigAtomic, CSigAtomic) -> g -> (CSigAtomic, g) # random :: RandomGen g => g -> (CSigAtomic, g) # randomRs :: RandomGen g => (CSigAtomic, CSigAtomic) -> g -> [CSigAtomic] # randoms :: RandomGen g => g -> [CSigAtomic] # randomRIO :: (CSigAtomic, CSigAtomic) -> IO CSigAtomic # randomIO :: IO CSigAtomic # | |
Random CIntPtr | |
Defined in System.Random | |
Random CUIntPtr | |
Defined in System.Random | |
Random CIntMax | |
Defined in System.Random | |
Random CUIntMax | |
Defined in System.Random | |
Random a => Random [a] # | Lists |
(Random a, Random b) => Random (a, b) # | Pairs |
Defined in Quipper.Utils.Sampling | |
(Random a, Random b, Random c) => Random (a, b, c) # | Triples |
Defined in Quipper.Utils.Sampling | |
(Random a, Random b, Random c, Random d) => Random (a, b, c, d) # | 4-Tuples |
Defined in Quipper.Utils.Sampling randomR :: RandomGen g => ((a, b, c, d), (a, b, c, d)) -> g -> ((a, b, c, d), g) # random :: RandomGen g => g -> ((a, b, c, d), g) # randomRs :: RandomGen g => ((a, b, c, d), (a, b, c, d)) -> g -> [(a, b, c, d)] # randoms :: RandomGen g => g -> [(a, b, c, d)] # randomRIO :: ((a, b, c, d), (a, b, c, d)) -> IO (a, b, c, d) # | |
(Random a, Random b, Random c, Random d, Random e) => Random (a, b, c, d, e) # | 5-Tuples |
Defined in Quipper.Utils.Sampling randomR :: RandomGen g => ((a, b, c, d, e), (a, b, c, d, e)) -> g -> ((a, b, c, d, e), g) # random :: RandomGen g => g -> ((a, b, c, d, e), g) # randomRs :: RandomGen g => ((a, b, c, d, e), (a, b, c, d, e)) -> g -> [(a, b, c, d, e)] # randoms :: RandomGen g => g -> [(a, b, c, d, e)] # randomRIO :: ((a, b, c, d, e), (a, b, c, d, e)) -> IO (a, b, c, d, e) # | |
(Random a, Random b, Random c, Random d, Random e, Random f) => Random (a, b, c, d, e, f) # | 6-Tuples |
Defined in Quipper.Utils.Sampling randomR :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> ((a, b, c, d, e, f), g) # random :: RandomGen g => g -> ((a, b, c, d, e, f), g) # randomRs :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> [(a, b, c, d, e, f)] # randoms :: RandomGen g => g -> [(a, b, c, d, e, f)] # randomRIO :: ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> IO (a, b, c, d, e, f) # | |
(Random a, Random b, Random c, Random d, Random e, Random f, Random g) => Random (a, b, c, d, e, f, g) # | 7-Tuples |
Defined in Quipper.Utils.Sampling randomR :: RandomGen g0 => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g0 -> ((a, b, c, d, e, f, g), g0) # random :: RandomGen g0 => g0 -> ((a, b, c, d, e, f, g), g0) # randomRs :: RandomGen g0 => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g0 -> [(a, b, c, d, e, f, g)] # randoms :: RandomGen g0 => g0 -> [(a, b, c, d, e, f, g)] # randomRIO :: ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> IO (a, b, c, d, e, f, g) # |
Functions
sample_all :: Interval a => a -> a -> [a] Source #
:
returns a list of all elements from the range (min,max). This
is actually just a synonym of sample_all
min maxinterval
.
sample_step :: (Integral a, Integral b, Interval c) => a -> b -> c -> c -> [c] Source #
:
returns every nth element from the range (min,max), starting
with the kth element.sample_step
n k min max
sample_random :: (Random a, RandomGen g) => g -> a -> a -> [a] Source #
:
returns an infinite list of random samples from the range
(min,max), using the random number generator g.sample_random
g min max
sample_all0 :: (Zero a, Interval a) => a -> [a] Source #
A variant of sample_all
that omits the min argument, and uses
the zero
element of the type instead.
sample_step0 :: (Integral a, Integral b, Zero c, Interval c) => a -> b -> c -> [c] Source #
A variant of sample_step
that omits the min argument, and uses
the zero
element of the type instead.
sample_random0 :: (Random a, Zero a, RandomGen g) => g -> a -> [a] Source #
A variant of sample_random
that omits the min argument, and uses
the zero
element of the type instead.
Orphan instances
Random () # | 0-tuples |
Random a => Random [a] # | Lists |
(Random a, Random b) => Random (a, b) # | Pairs |
(Random a, Random b, Random c) => Random (a, b, c) # | Triples |
(Random a, Random b, Random c, Random d) => Random (a, b, c, d) # | 4-Tuples |
randomR :: RandomGen g => ((a, b, c, d), (a, b, c, d)) -> g -> ((a, b, c, d), g) # random :: RandomGen g => g -> ((a, b, c, d), g) # randomRs :: RandomGen g => ((a, b, c, d), (a, b, c, d)) -> g -> [(a, b, c, d)] # randoms :: RandomGen g => g -> [(a, b, c, d)] # randomRIO :: ((a, b, c, d), (a, b, c, d)) -> IO (a, b, c, d) # | |
(Random a, Random b, Random c, Random d, Random e) => Random (a, b, c, d, e) # | 5-Tuples |
randomR :: RandomGen g => ((a, b, c, d, e), (a, b, c, d, e)) -> g -> ((a, b, c, d, e), g) # random :: RandomGen g => g -> ((a, b, c, d, e), g) # randomRs :: RandomGen g => ((a, b, c, d, e), (a, b, c, d, e)) -> g -> [(a, b, c, d, e)] # randoms :: RandomGen g => g -> [(a, b, c, d, e)] # randomRIO :: ((a, b, c, d, e), (a, b, c, d, e)) -> IO (a, b, c, d, e) # | |
(Random a, Random b, Random c, Random d, Random e, Random f) => Random (a, b, c, d, e, f) # | 6-Tuples |
randomR :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> ((a, b, c, d, e, f), g) # random :: RandomGen g => g -> ((a, b, c, d, e, f), g) # randomRs :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> [(a, b, c, d, e, f)] # randoms :: RandomGen g => g -> [(a, b, c, d, e, f)] # randomRIO :: ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> IO (a, b, c, d, e, f) # | |
(Random a, Random b, Random c, Random d, Random e, Random f, Random g) => Random (a, b, c, d, e, f, g) # | 7-Tuples |
randomR :: RandomGen g0 => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g0 -> ((a, b, c, d, e, f, g), g0) # random :: RandomGen g0 => g0 -> ((a, b, c, d, e, f, g), g0) # randomRs :: RandomGen g0 => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g0 -> [(a, b, c, d, e, f, g)] # randoms :: RandomGen g0 => g0 -> [(a, b, c, d, e, f, g)] # randomRIO :: ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> IO (a, b, c, d, e, f, g) # |