Use HSpec and QuickCheck to verify Data.Monoid properties
I'm trying to use HSpec and QuickCheck to verify properties of Monoids (associativity and identity element). I am going to verify particular instances, but would like to keep most of the code polymorphic. This is what I came up with after several hours: module Test where import Test.Hspec import Test.QuickCheck import Data.Monoid instance (Arbitrary a) => Arbitrary (Sum a) where arbitrary = fmap Sum arbitrary instance (Arbitrary a) => Arbitrary (Product a) where arbitrary = fmap Product arbitrary prop_Monoid_mappend_mempty_x x = mappend mempty x === x sumMonoidSpec = it "mappend mempty x = x"