[Haskell-cafe] Re: QuickCheck: Arbitrary for a complex type

Joel Reymont joelr1 at gmail.com
Wed Apr 4 11:47:22 EDT 2007


I got this simple example working so I think I have my question  
answered.

Now I just have to learn to write generators of my own to produce  
valid and invalid input for my parser.

module Foo where

import Control.Monad
import System.Random
import Test.QuickCheck

data Foo
     = Foo Int
     | Bar
     | Baz
       deriving Show

instance Arbitrary Foo where
     coarbitrary = undefined
     arbitrary   = oneof [ return Bar
                         , return Baz
                         , liftM Foo arbitrary
                         ]

gen' rnd = generate 10000 rnd $ vector 5 :: [Foo]

gen =
     do { rnd <- newStdGen
        ; return $ gen' rnd
        }

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list