Generic default series and coseries #4

Merged
merged 2 commits into from Nov 26, 2011

Projects

None yet

2 participants

@basvandijk

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 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

@feuerbach
Owner

Hi Bas,

This looks very interesting, thanks!

Will merge after having a closer look.

@feuerbach feuerbach merged commit 43e0a48 into feuerbach:master Nov 26, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment