
Hello It always puzzled me why there are no packages for for testing general type classes laws. (Monoid laws, monad laws etc). It looks like ideal case for quickcheck and smallcheck. I'm glad to present package quickcheck-properties[1]. It containt set of generic properties for semiroups, monoids, groups and unsatisfactory imlementatation of functor's properties. Despite its name package do not depend on quickcheck and could be used with smallcheck as well. ==================== Examples ==================== Here are few examples:
quickCheck $ eq $ prop_Monoid (T :: T [Int]) +++ OK, passed 100 tests. quickCheck $ eq $ prop_Monoid (T :: T (Maybe [Int])) +++ OK, passed 100 tests.
prop_Monoid tests all monoid properties: associativity, left and right identity. T is used to fix type of monoid to test. It could be done with type signature for prop_Monoid but writing signature for three parameter function is just too cumbersome. eq compares expression in properties using == operator. Many (most?) of properties have form
expression = another expression
Easiest solution is to compare them with ==. But is's not satisfactory. Data type may not have Eq instance. Eq instance may provide structural equality but some form of equivalince is needed. etc. It's left to library user to decide how to compare values. In this contrived example lists are compared by length.
eqOn length $ prop_Monoid (T :: T [Int])
==================== Problems ==================== There are unsolved problems. So it's announcement with question. Functor/Applicative/Monads laws involve arbitrary functions. It would be natural to generate them using quickcheck but I don't know how to generate random functions. Any suggestions? [1] http://hackage.haskell.org/package/quickcheck-properties -- Aleksey Khudyakov