packages with orphaned instances only

Edward Z. Yang ezyang at MIT.EDU
Sat Jan 8 22:45:14 CET 2011

Tangential to the discussion, there is a nice idiom for using an alternative
typeclass that works well in the Quickcheck case: newtypes.

For example, if I have a test function:

testString :: String -> Bool
testString s = f1 s == f2 s

and the default instance of String isn't doing what I want, I could
define a custom arbitrary method:

testString = do
    s <- myArbitraryStr
    return (f1 s == f2 s)

But I could also newtype String, define an instance for that newtype,
and use either of these (in my opinion) nice alternative spellings:

testString (MyString s) = ...
testString = do
    MyString s <- arbitrary

I especially like the first form.


More information about the Libraries mailing list