purescript-contrib / purescript-quickcheck-laws

QuickCheck powered law tests for PureScript's core typeclasses.
MIT License
25 stars 18 forks source link

Add minimal example to docs? #47

Closed kurtmilam closed 2 years ago

kurtmilam commented 5 years ago

Thanks for the work on this library!

If you're open to it, I'd like to submit a PR to add a minimal example to the docs. I was thinking something along the lines of this:

data Pair a = Pair a a
derive instance eq1Pair :: Eq1 Pair
derive instance eqPair :: Eq a => Eq (Pair a)
instance arbPair :: Arbitrary a => Arbitrary (Pair a) where
  arbitrary = Pair <$> arbitrary <*> arbitrary
instance functorPair :: Functor Pair where
  map f (Pair x y) = Pair (f x) (f y)

prxPair :: Proxy2 Pair
prxPair = Proxy2

main :: Effect Unit
main = do do checkLaws "Pair" (checkFunctor prxPair)

If you're open to adding an example to the docs, I assume it would be straightforward to adapt the example for purescript-strongcheck-laws as well.

I guess an even more minimal example would be to test an existing type that has a Functor instance, but I had a difficult time getting the Eq and Arbitrary instances right for a custom type in order to be able to test its Functor instance with QuickCheck.

garyb commented 5 years ago

Adding an example sounds good to me, sure!

There is also the whole test folder that exercise a good deal of the core data types using the library, it's probably worth adding a line to the README about using that as a reference too.