Find Related products on Amazon

Shop on Amazon

Falsify: Hypothesis-Inspired Shrinking for Haskell (2023)

Published on: 2025-08-18 19:41:29

Consider this falsify property test that tries to verify the (obviously false) property that all elements of all lists of up to 10 binary digits are the same (we will explain the details below; hopefully the intent is clear): prop_list :: Property () () = do prop_list n <- gen $ Gen.integral $ Range.between ( 0 , 10 ) genGen.integralRange.between ( <- gen $ replicateM n $ Gen.int $ Range.between ( 0 , 1 ) xsgenreplicateM nGen.intRange.between ( $ P.pairwise P.eq .$ ( "xs" , xs) assertP.pairwise P.eq, xs) we might get a counter-example such as this: failed after 9 shrinks (xs !! 0) /= (xs !! 1) xs : [0,1] xs !! 0: 0 xs !! 1: 1 More interesting than the counter-example itself is how falsify arrived at that counter-example; if we look at the shrink history ( --falsify-verbose ), we see that the list shrunk as follows: [1,1,0,1,0,1] ~> [1,1,0] -- shrink the list length ~> [0,1,0] -- shrink an element of the list ~> [0,1] -- shrink the list length again The test runner is able to go b ... Read full article.