QuickCheck has a special Test.QuickCheck.Function module for generating "functions" that can be shown (as well as "compressed", as QuickCheck simplifies its counterexamples). You can convert them to regular functions with apply . For example, if you have a file:
import Test.QuickCheck import Test.QuickCheck.Function test :: Fun Int Int -> Int -> Bool test _ _ = True test2 :: Fun Int Int -> Int -> Bool test2 fx = apply fx == x
Then in GHCi:
*Main> quickCheck test +++ OK, passed 100 tests. *Main> quickCheck test2 *** Failed! Falsifiable (after 2 tests and 3 shrinks): {_->0} 1
In fact, you can define a Show instance for the functions themselves and use it. But if your input type is not the final type of the Bool type, you cannot print all the information about the function in this way. You can import a dummy instance that does not show useful information from Text.Show.Functions .
However, the type of Test.QuickCheck.Function.Fun used above looks like it was designed to give the basic information a lot more succinctly, so I would certainly use it myself if possible.
Γrjan Johansen
source share