
On 17 July 2011 23:42, bob zhang
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.h... where the DotStatements type can have DotSubGraph values, which in turn have DotStatements). -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com