feuerbach/smallcheck — pull request #4 by basvandijk (2011-11-23 14:25:08+00:00)
Title: Generic default series and coseries

Hi Roman,

Attached is a patch for `smallcheck` which adds generic default implementations for the `series` and `coseries` methods of `Serial`. It uses the new [GHC Generics](http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-programming.html) feature.

With this patch a user doesn't have to write his own `Serial` instance:

```
{-# LANGUAGE DeriveGeneric #-}

import Test.SmallCheck
import GHC.Generics

data Tree a = Null | Fork (Tree a) a (Tree a) deriving (Show, Generic)

instance (Serial a) => Serial (Tree a)
```

For example:

```
> (series :: Series (Tree ())) 0
[]
> (series :: Series (Tree ())) 1
[Null]
> (series :: Series (Tree ())) 2
[Null,Fork Null () Null]
> (series :: Series (Tree ())) 3
[Null,Fork Null () Null,Fork Null () (Fork Null () Null),Fork (Fork Null () Null) () Null,Fork (Fork Null () Null) () (Fork Null () Null)]
```

I didn't yet test this the generic `coseries` thoroughly but I think it should work.

Regards,

Bas