[Haskell-cafe] QuickCheck

Ryan Ingram ryani.spam at gmail.com
Mon Mar 17 04:47:04 EDT 2008


2008/3/16 Sebastian Sylvan <sebastian.sylvan at gmail.com>:
> featureGenNormal = do
>     id <- stringGen
>     name <- stringGen
>     featuretype <- arbitrary
>      grouptype <- arbitrary
>     children <- arbitrary
>     properties <- listGen stringGen
>     return (Feature id name featuretype grouptype children properties)
>
>
> Note that we use "arbitrary" to generate the list of children recursively.

Also, you can shorten this significantly with liftM or ap (from Control.Monad):
> featureGenNormal = liftM6 Feature stringGen stringGen arbitrary arbitrary arbitrary (listGen stringGen)
> featureGenNormal = return Feature `ap` stringGen `ap` stringGen `ap` arbitrary `ap` arbitrary `ap` listGen stringGen


More information about the Haskell-Cafe mailing list