Hi! I usually use the function &#39;sized&#39; for this. The function would look something like this:<br><br>myIntGen :: Gen Int<br>myIntGen = sized $ \n -&gt; choose (0,f n)<br><br>where
 &#39;f&#39; is a function that uses the size value to generate an upper value 
for your random range. I usually use ^2 or sqrt or something like that 
depending on my needs.<br>
<br>Hope it helps!<br><br>Best regards, Øystein<br><br><div class="gmail_quote">On Mon, Jul 25, 2011 at 6:31 AM, Mark Spezzano <span dir="ltr">&lt;<a href="mailto:mark.spezzano@chariot.net.au">mark.spezzano@chariot.net.au</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi Kevin,<br>
<br>
Thanks for the response. The first part works well with minor modifications.<br>
<br>
Part 2 is still a bit vague to me. I basically want to &quot;clamp&quot; the Integers generated within the Queue to between 0 and some positive number. At present they&#39;re giving me numbers all over the place (specifically negative number)<br>

<br>
Thanks<br>
<font color="#888888"><br>
Mark<br>
</font><div><div></div><div class="h5"><br>
<br>
On 25/07/2011, at 4:44 AM, Kevin Quick wrote:<br>
<br>
&gt; On Sun, 24 Jul 2011 07:30:56 -0700, Mark Spezzano &lt;<a href="mailto:mark.spezzano@chariot.net.au">mark.spezzano@chariot.net.au</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Hi all,<br>
&gt;&gt;<br>
&gt;&gt; I would appreciate it if someone can point me in the right direction with the following problem.<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m deliberately implementing a naive Queues packages that uses finite lists as the underlying representation. I&#39;ve already read through Hughes&#39; paper and the article in The Fun of Programming, but I&#39;m still having some difficulties. Specifically:<br>

&gt;&gt;<br>
&gt;&gt; 1. I have a newtype Queue a = Queue [a] and I want to generate Queues of random Integers that are also of random size. How do I do this in QuickCheck? I guess that  I need to write a generator and then make my &quot;Queue a&quot; concrete type an instance of Arbitrary? How?<br>

&gt;<br>
&gt; Mark,<br>
&gt;<br>
&gt; One of the great things about QuickCheck is that it is automatically compositional.<br>
&gt; What I mean by this is that all you need in your instance is how to form a &quot;Queue [a]&quot; given &quot;[a]&quot;, because there are already QuickCheck instances for forming lists, and as long as a is pretty standard (Integers is fine) then there&#39;s likely an Arbitrary instance for that as well.<br>

&gt;<br>
&gt; So (from my head, not actually tested in GHC):<br>
&gt;<br>
&gt; import Control.Applicative<br>
&gt; import Test.QuickCheck<br>
&gt;<br>
&gt; instance Arbitrary Queue where<br>
&gt;   arbitrary = Queue &lt;$&gt; arbitrary<br>
&gt;<br>
&gt; Then you can use this as:<br>
&gt;<br>
&gt; testProperty &quot;length is something&quot; propQInts<br>
&gt;<br>
&gt; propQInts t = length t == ....<br>
&gt;    where types = (t :: Queue Integers)<br>
&gt;<br>
&gt; The where clause is a fancy way of specifying what the type of t should be without having to express the overall type of propQInts.  You could use a more conventional type specification as well.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; 2. If I wanted to specify/constrain the ranges of random Integers generated, how would I do this?<br>
&gt;<br>
&gt; Probably something like this:<br>
&gt;<br>
&gt; instance Arbitrary Queue where<br>
&gt;    arbitrary = do li &lt;- listOf $ arbitrary<br>
&gt;                  lr &lt;- liftM $ map rangelimit li<br>
&gt;                  return $ Queue lr<br>
&gt;                where rangelimit n = case (n &lt; LOW, n &gt; HIGH) of<br>
&gt;                                       (True,_) -&gt; LOW<br>
&gt;                                       (_,True) -&gt; HIGH<br>
&gt;                                       _ -&gt; n<br>
&gt;<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; 3. If I wanted to specify/constrain the Queue sizes how would I do this?<br>
&gt;<br>
&gt; Similar to #2.  Perhaps:<br>
&gt;<br>
&gt;   arbitrary = arbitrary &gt;&gt;= (return . Queue . take CNT . listOf)<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; -KQ<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Mvh Øystein Kolsrud<br>