Safe Haskell | None |
---|
Libraries.Sampling
Description
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
)
- class Interval a where
- class Zero a where
- 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)].
Minimal complete definition
Methods
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 () # | |
Interval IntM # | |
Interval a => Interval [a] # | |
(Interval a, Interval b) => Interval (a, b) # | |
(Interval a, Interval b, Interval c) => Interval (a, b, c) # | |
(Interval a, Interval b, Interval c, Interval d) => Interval (a, b, c, d) # | |
(Interval a, Interval b, Interval c, Interval d, Interval e) => Interval (a, b, c, d, e) # | |
(Interval a, Interval b, Interval c, Interval d, Interval e, Interval f) => Interval (a, b, c, d, e, f) # | |
(Interval a, Interval b, Interval c, Interval d, Interval e, Interval f, Interval g) => Interval (a, b, c, d, e, f, g) # | |
Zero class
Types in the Zero
class have an "origin", i.e., an element
that can conveniently serve as the starting point for intervals.
Minimal complete definition
Methods
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 () # | |
Zero IntM # | |
Zero a => Zero [a] # | |
(Zero a, Zero b) => Zero (a, b) # | |
(Zero a, Zero b, Zero c) => Zero (a, b, c) # | |
(Zero a, Zero b, Zero c, Zero d) => Zero (a, b, c, d) # | |
(Zero a, Zero b, Zero c, Zero d, Zero e) => Zero (a, b, c, d, e) # | |
(Zero a, Zero b, Zero c, Zero d, Zero e, Zero f) => Zero (a, b, c, d, e, f) # | |
(Zero a, Zero b, Zero c, Zero d, Zero e, Zero f, Zero g) => Zero (a, b, c, d, e, f, g) # | |
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
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 |
(Random a, Random b, Random c, Random d, Random e) => Random (a, b, c, d, e) # | 5-Tuples |
(Random a, Random b, Random c, Random d, Random e, Random f) => Random (a, b, c, d, e, f) # | 6-Tuples |
(Random a, Random b, Random c, Random d, Random e, Random f, Random g) => Random (a, b, c, d, e, f, g) # | 7-Tuples |