[Haskell-cafe] derive + quickCheck

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Tue Jul 19 23:47:31 CEST 2011


On 19 July 2011 21:23, bob zhang <bobzhang1988 at gmail.com> wrote:
> Hi,
>   thank you .
>   I read your souce, I found the depth is only 2, right?
>  like data A = [A]|String, any easy way to control the maximum_depth of
> generated data?

You could always use an Int parameter instead of a Bool and have it
count down to 0, in which case you stop generating recursive
structures.

>
> Regards,bob
> 于 11-7-17 下午8:13, Ivan Lazar Miljenovic 写道:
>>
>> 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