take :: Int -> [a] -> [a] sort :: Ord a => [a] -> [a]by binding them to the following types:
take :: Int -> [A] -> [A] sort :: [A] -> [A]This type is homomorphic to Nat6, B, C, D, E and F. It is instance to several typeclasses so that it can be used to test functions with type contexts.
instance Listable <Type> where tiers = ... \/ cons<N> <Cons> `addWeight` <W> \/ ...Typically used as an infix operator when defining Listable instances:
> [ xs, ys, zs, ... ] `addWeight` 1 [ [], xs, ys, zs, ... ]
> [ xs, ys, zs, ... ] `addWeight` 2 [ [], [], xs, ys, zs, ... ]
> [ [], xs, ys, zs, ... ] `addWeight` 3 [ [], [], [], [], xs, ys, zs, ... ]`addWeight` n is equivalent to n applications of delay.
instance (Listable a, Eq b) => Eq (a -> b) where (==) = areEqualFor 12This catches errors and undefined values and treats them as equal.
list :: [Alpha] = "aAbBcC..."
> check $ \(Alpha c) -> isAlpha c +++ OK, passed 52 tests (exhausted).Equivalent to Letter.
list :: [AlphaNum] = "0a1A2b3B4c..."
> check $ \(AlphaNum c) -> isAlphaNum c +++ OK, passed 62 tests (exhausted).
holds 1000 propertyTrue indicates success. False indicates a bug. For example:
> import Data.List (sort) > holds 1000 $ \xs -> length (sort xs) == length (xs::[Int]) TrueTo get the smallest counterExample by testing up to a thousand values, we evaluate:
counterExample 1000 propertyNothing indicates no counterexample was found, a Just value indicates a counterexample. For instance:
> import Data.List (union) > counterExample 1000 $ \xs ys -> union xs ys == union ys (xs :: [Int]) Just ["[]","[0,0]"]The suggested values for the number of tests to use with LeanCheck are 500, 1 000 or 10 000. LeanCheck is memory intensive and you should take care if you go beyond that. The function check can also be used to test and report counterexamples.
> check $ \xs ys -> union xs ys == union ys (xs :: [Int]) *** Failed! Falsifiable (after 4 tests): [] [0,0]Arguments of properties should be instances of the Listable typeclass. Listable instances are provided for the most common Haskell types. New instances are easily defined (see Listable for more info).
tiers = cons<N> ConstructorA \/ cons<N> ConstructorB \/ ... \/ cons<N> ConstructorZwhere 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 MyConsDThe instance for Hutton's Razor is given by:
data Expr = Val Int | Add Expr Expr instance Listable Expr where tiers = cons1 Val \/ cons2 AddInstances 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.
Bool
Listable a => a -> Bool
(Listable a, Listable b) => a -> b -> Bool
(Listable a, Listable b, Listable c) => a -> b -> c -> Bool
(Listable a, Listable b, Listable c, ...) => a -> b -> c -> ... -> Bool
Int -> Bool
String -> [Int] -> Bool
bagCons Bag
bagsOf [[0],[1],[2],...] = [ [[]] , [[0]] , [[0,0],[1]] , [[0,0,0],[0,1],[2]] , [[0,0,0,0],[0,0,1],[0,2],[1,1],[3]] , [[0,0,0,0,0],[0,0,0,1],[0,0,2],[0,1,1],[0,3],[1,2],[4]] , ... ]
concatT [ [xss0, yss0, zss0, ...] , [xss1, yss1, zss1, ...] , [xss2, yss2, zss2, ...] , ... ] = xss0 \/ yss0 \/ zss0 \/ ... \/ delay (xss1 \/ yss1 \/ zss1 \/ ... \/ delay (xss2 \/ yss2 \/ zss2 \/ ... \/ (delay ...)))(cf. concatMapT)