> fails 1000 $ \xs -> xs ++ ys == ys ++ xs True
> holds 1000 $ \xs -> length (sort xs) == length xs FalseThis is the negation of holds.
filterT p [xs, yz, zs, ...] = [filter p xs, filter p ys, filter p zs]
filterT odd tiers = [[], [1], [-1], [], [], [3], [-3], [], [], [5], ...]
> fromError 0 (15 :: Int) 15
> fromError 0 (undefined :: Int) 0
> 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]
> 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.
> take 6 $ funToListMaybe $ head :: [Maybe Int] [Nothing,Just 0,Just 0,Just 1,Just 0,Just 0]This uses errorToNothing and consequently unsafePerformIO.
> import Test.LeanCheck > import Test.LeanCheck.Function
> check $ \f p xs -> filter p (map f xs) == map f (filter p xs :: [Int]) *** Failed! Falsifiable (after 36 tests): \_ -> 0 \x -> case x of 0 -> True _ -> False [1]
> check $ \f p xs -> filter p (map f xs) == map f (filter p xs :: [Bool]) *** Failed! Falsifiable (after 20 tests): \_ -> False \x -> case x of False -> False True -> True [True]
> check $ \f z xs -> foldr f z xs == foldl f z (xs :: [Int]) *** Failed! Falsifiable (after 75 tests): \x _ -> case x of 0 -> 1 _ -> 0 0 [0,0]Warning: this is only intended to be used in testing modules. Avoid importing this on modules that are used as libraries. The Listable and Show function instance are defined in, respectively: The Show instance will work for all functions whose return types are instances of ShowFunction from Test.LeanCheck.Function.ShowFunction.
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]] , ... ]
> checkFor 1000 $ \xs -> sort (sort xs) == sort (xs::[Int]) +++ OK, passed 1000 tests.Test exhaustion is reported when the configured number of tests is larger than the number of available test values:
> checkFor 3 $ \p -> p == not (not p) +++ OK, passed 2 tests (exhausted).
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.
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, ...]
listsOf [[]] = [[[]]]
listsOf [[x]] = [ [[]] , [[x]] , [[x,x]] , [[x,x,x]] , ... ]
listsOf [[x],[y]] = [ [[]] , [[x]] , [[x,x],[y]] , [[x,x,x],[x,y],[y,x]] , ... ]
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]] , ... ]
noDupListsOf [[0],[1],[2],...] == [ [[]] , [[0]] , [[1]] , [[0,1],[1,0],[2]] , [[0,2],[2,0],[3]] , ... ]
> [ [], [], ..., xs, ys, zs, ... ] `ofWeight` 1 [ [], xs, ys, zs, ... ]
> [ xs, ys, zs, ... ] `ofWeight` 2 [ [], [], xs, ys, zs, ... ]
> [ [], xs, ys, zs, ... ] `ofWeight` 3 [ [], [], [], xs, ys, zs, ... ]Typically used as an infix operator when defining Listable instances:
instance Listable <Type> where tiers = ... \/ cons<N> <Cons> `ofWeight` <W> \/ ...Warning: do not apply `ofWeight` 0 to recursive data structure constructors. In general this will make the list of size 0 infinite, breaking the tier invariant (each tier must be finite). `ofWeight` n is equivalent to reset followed by n applications of delay.
setsOf [[0],[1],[2],...] = [ [[]] , [[0]] , [[1]] , [[0,1],[2]] , [[0,2],[3]] , [[0,3],[1,2],[4]] , [[0,1,2],[0,4],[1,3],[5]] , ... ]Can be used in the constructor of specialized Listable instances. For Set (from Data.Set), we would have:
instance Listable a => Listable (Set a) where tiers = mapT fromList $ setsOf tiers