list package:leancheck

This module is part of LeanCheck, a simple enumerative property-based testing library. This module exports functions to convert functions to lists of return values and producing comparisons between functions.
Listing of Floating values. This can be used as the implementation of list for Floating types.
listFloating :: [Double]  =
[0.0, 1.0, -1.0, 0.5, -0.5, 2.0, Infinity, -Infinity, -2.0, 0.333, ...]
This follow the same Calkin-Wilf sequence of listFractional but positive and negative infinities are artificially included after two. NaN and -0 are excluded from this enumeration.
Listing of Fractional values. This can be used as the implementation of list for Fractional types.
listFractional :: [[Rational]]  =
[0 % 1, 1 % 1, (-1) % 1, 1 % 2, (-1) % 2, 2 % 1, (-2) % 1, 1 % 3, ...]
All rationals are included without repetition in their most simple form. This is the Calkin-Wilf sequence computed with the help of the fusc function (EWD 570). This also works for unsigned types that wrap around zero, yielding:
listFractional :: [Ratio Word]  =
[0 % 1, 1 % 1, 1 % 2, 2 % 1, 1 % 3, 3 % 2, 2 % 3, 3 % 1, 1 % 4, ...]
Tiers of Integral values. Can be used as a default implementation of list for Integral types. For types with negative values, like Int, the list starts with 0 then intercalates between positives and negatives.
listIntegral  =  [0, 1, -1, 2, -2, 3, -3, 4, -4, ...]
For types without negative values, like Word, the list starts with 0 followed by positives of increasing magnitude.
listIntegral  =  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...]
This function will not work for types that throw errors when the result of an arithmetic operation is negative such as Natural. For these, use [0..] as the list implementation.
Takes as argument tiers of element values; returns tiers of lists of elements.
listsOf [[]]  =  [[[]]]
listsOf [[x]]  =  [ [[]]
, [[x]]
, [[x,x]]
, [[x,x,x]]
, ...
]
listsOf [[x],[y]]  =  [ [[]]
, [[x]]
, [[x,x],[y]]
, [[x,x,x],[x,y],[y,x]]
, ...
]
Takes as argument an integer length and tiers of element values; returns tiers of lists of element values of the given length.
listsOfLength 3 [[0],[1],[2],[3],[4]...] =
[ [[0,0,0]]
, [[0,0,1],[0,1,0],[1,0,0]]
, [[0,0,2],[0,1,1],[0,2,0],[1,0,1],[1,1,0],[2,0,0]]
, ...
]
Given a constructor that takes a list, return tiers of applications of this constructor. This is basically a type-restricted version of cons1. You should use cons1 instead: this serves more as an illustration of how setCons and bagCons work (see source).
A type is Listable when there exists a function that is able to list (ideally all of) its values. Ideally, instances should be defined by a tiers function that returns a (potentially infinite) list of finite sub-lists (tiers): the first sub-list contains elements of size 0, the second sub-list contains elements of size 1 and so on. Size here is defined by the implementor of the type-class instance. For algebraic data types, the general form for tiers is
tiers  =  cons<N> ConstructorA
\/ cons<N> ConstructorB
\/ ...
\/ cons<N> ConstructorZ
where N is the number of arguments of each constructor A...Z. Here is a datatype with 4 constructors and its listable instance:
data MyType  =  MyConsA
|  MyConsB Int
|  MyConsC Int Char
|  MyConsD String

instance Listable MyType where
tiers =  cons0 MyConsA
\/ cons1 MyConsB
\/ cons2 MyConsC
\/ cons1 MyConsD
The instance for Hutton's Razor is given by:
data Expr  =  Val Int
|  Add Expr Expr

instance Listable Expr where
tiers  =  cons1 Val
\/ cons2 Add
Instances can be alternatively defined by list. In this case, each sub-list in tiers is a singleton list (each succeeding element of list has +1 size). The function deriveListable from Test.LeanCheck.Derive can automatically derive instances of this typeclass. A Listable instance for functions is also available but is not exported by default. Import Test.LeanCheck.Function if you need to test higher-order properties.
This module is part of LeanCheck, a simple enumerative property-based testing library. This module exports a Listable instance for functions. LeanCheck provides one definition of Listable functions:
  • Test.LeanCheck.Function.Listable.ListsOfPairs: considers functions as a finite list of exceptional input-output cases to a default value (list of pairs of arguments and results). This is the LeanCheck default, and is the one exported by this module.
In the future, alternative instances could be provided in sub-modules. Warning: this is only intended to be used in testing modules. Avoid importing this on modules that are used as libraries.
This module is part of LeanCheck, a simple enumerative property-based testing library. This module exports a Listable instance for function enumeration via lists of pairs. This module considers functions as a finite list of exceptional input-output cases to a default value (list of pairs of arguments and results).
This module is part of LeanCheck, a simple enumerative property-based testing library. This module exports means to enumerate functions via lists of pairs. This module considers functions as a finite list of exceptional input-output cases to a default value (list of pairs of arguments and results).
Derives a Listable instance for a given type Name. Consider the following Stack datatype:
data Stack a  =  Stack a (Stack a) | Empty
Writing
deriveListable ''Stack
will automatically derive the following Listable instance:
instance Listable a => Listable (Stack a) where
tiers  =  cons2 Stack \/ cons0 Empty
Warning: if the values in your type need to follow a data invariant, the derived instance won't respect it. Use this only on "free" datatypes. Needs the TemplateHaskell extension.
Derives a Listable instance for a given type Name cascading derivation of type arguments as well. Consider the following series of datatypes:
data Position  =  CEO | Manager | Programmer

data Person  =  Person
{  name :: String
,  age :: Int
,  position :: Position
}

data Company  =  Company
{  name :: String
,  employees :: [Person]
}
Writing
deriveListableCascading ''Company
will automatically derive the following three Listable instances:
instance Listable Position where
tiers  =  cons0 CEO \/ cons0 Manager \/ cons0 Programmer

instance Listable Person where
tiers  =  cons3 Person

instance Listable Company where
tiers  =  cons2 Company
Given a constructor that takes a list with no duplicate elements, return tiers of applications of this constructor.
Takes as argument tiers of element values; returns tiers of lists with no repeated elements.
noDupListsOf [[0],[1],[2],...] ==
[ [[]]
, [[0]]
, [[1]]
, [[0,1],[1,0],[2]]
, [[0,2],[2,0],[3]]
, ...
]
Given a type Name, derives an expression to be placed as the result of list:
concat $ consN C1 \/ consN C2 \/ ... \/ consN CN
Same as deriveListable but does not warn when the requested instance already exists. The function deriveListable is preferable in most situations.
Converts a function to a list of result values for each Listable argument value.
> list  ::  [Bool]
[False,True]
> funToList not
[True,False]
> list  ::  [(Bool,Bool)]
[(False,False),(False,True),(True,False),(True,True)]
> funToList $ uncurry (&&)
[False,False,False,True]
This function may return an infinite list, use take as required.
> take 10 $ list  ::  [Int]
[0,1,-1,2,-2,3,-3,4,-4,5]
> take 10 $ funToList (+1)  ::  [Int]
[1,2,0,3,-1,4,-2,5,-3,6]
Converts a function to a list of Just result values or Nothing on error.
> take 6 $ funToListEither $ head :: [Either String Int]
[Left "Prelude.head: empty list",Right 0,Right 0,Right 1,Right 0,Right 0]
This uses errorToLeft and consequently unsafePerformIO.
Converts a function to a list of Just result values or Nothing on error.
> take 6 $ funToListMaybe $ head :: [Maybe Int]
[Nothing,Just 0,Just 0,Just 1,Just 0,Just 0]
This uses errorToNothing and consequently unsafePerformIO.
A generic implementation of list for instances of Generic. Use it to define your Listable instances like so:
instance Listable MyType where
list  =  genericList
Consider using genericTiers instead of this (unless you know what you're doing).