[Haskell-cafe] Ensuring Type Class instances follow the 'rules'
Hemanth Kapila
saihemanth at gmail.com
Fri May 29 08:05:47 EDT 2009
Thanks Eugene and wren.
Serves me right, actually. The one chapter I skipped in RWH was the 11th one
called "Testing and Quality Assurance" thinking it is too boring.
On Fri, May 29, 2009 at 12:44 PM, wren ng thornton <wren at freegeek.org>wrote:
> Eugene Kirpichov wrote:
>
>> Use QuickCheck.
>>
>
> Also use SmallCheck or lazy SmallCheck.
>
> All of these are automatic tools that allow you to specify laws[1] and
> automatically generate values for testing the law. QuickCheck generates
> values randomly, which can be useful but is very often insufficient. Both
> versions of SmallCheck do exhaustive search of all values down to a bounded
> "depth" (lazy SmallCheck can often search deeper and faster).
>
> If you want to have decent assurances of correctness then use (lazy)
> SmallCheck. If you're dealing with a really branchy type which makes it
> prohibitive to search to any reasonable depth, then use QuickCheck in
> addition. Occasionally QuickCheck can be good for ferreting out really
> obscure corner cases, but SmallCheck is much better about guaranteeing you
> get all the basic cases.
>
>
> [1] e.g.
>
> prop_compare a b =
> compare a b == negateOrdering (compare b a)
> where
> negateOrdering LT = GT
> negateOrdering EQ = EQ
> negateOrdering GT = LT
>
> --
> Live well,
> ~wren
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090529/19511739/attachment.html
More information about the Haskell-Cafe
mailing list