[Haskell-cafe] derive + quickCheck

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Mon Jul 18 02:13:32 CEST 2011


On 17 July 2011 23:42, bob zhang <bobzhang1988 at gmail.com> wrote:
> Hi, all,
> I found derive + quickCheck very useful but I came across some problems.
> I used derive to derive instance of Arbitrary immeditaely, but sometimes the
> sample is non-terminating, which I mean the result is very very big.
>
> [snip]
>
> data JValue = JString String
> | JNumber Double
> | JBool Bool
> | JNull
> | JObject [(String, JValue)] --
> | JArray [JValue] --
> deriving (Eq,Ord,Show)
> $(derive makeArbitrary ''JValue)

Your JValue type is recursive; as such I highly suggest you manually
create the Arbitrary instances for it (e.g. a helper function with a
Bool parameter to indicate whether or not to create recursive calls;
see how I do it in
http://code.haskell.org/graphviz/Data/GraphViz/Testing/Instances/Canonical.hs
where the DotStatements type can have DotSubGraph values, which in
turn have DotStatements).

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com



More information about the Haskell-Cafe mailing list