GHC: Ticket #2065: QuickCheck: coarbitrary for Double and Float is broken.
http://ghc.haskell.org/trac/ghc/ticket/2065
<p>
The <tt>coarbitrary</tt> definition for these types is incompatible with the way they are generated. First, <tt>decodeFloat</tt> produces a pair <tt>(Integer, Int)</tt>, then the <tt>Integer</tt> is manipulated to be positive and then coerced to an <tt>Int</tt> using <tt>fromInteger</tt> and passed to variant. Even 'simple' values of type <tt>Double</tt> and <tt>Float</tt> (as produced by <tt>arbitrary</tt>) can have huge significands. In the case of Double, the resulting <tt>Int</tt> can be negative due to truncation. This causes an exception when <tt>variant</tt> uses '(!!)' with a negative index. Huge positive values are just as bad since they cause a space leak while evaluating <tt>variant</tt> with a huge index (and tend not to terminate due to memory constraints). An obvious fix is to use the QuickCheck-2 approach.
</p>
<p>
To reproduce, import Test.QuickCheck and Text.Show.Functions, then run:
</p>
<p>
<tt>verboseCheck ((\f a -> f a == f a) :: (Float -> Int) -> Float -> Bool)</tt>
</p>
<p>
This should pass a few tests before finding a space leak.
</p>
<p>
<tt>verboseCheck ((\f a -> f a == f a) :: (Double -> Int) -> Double -> Bool)</tt>
</p>
<p>
This should also pass a few, then it may find a space leak, or it may error with:
</p>
<p>
<tt>*** Exception: Prelude.(!!): negative index</tt>
</p>
<p>
Note that QuickCheck-2 has no problems here.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/2065
Trac 1.0.9iglooSat, 16 Feb 2008 01:26:51 GMTstatus changed; difficulty, resolution set
http://ghc.haskell.org/trac/ghc/ticket/2065#comment:1
http://ghc.haskell.org/trac/ghc/ticket/2065#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
Thanks for the report. However, if this works in QuickCheck 2 then I think we should consider this bug closed. If it is important to you that it works in QC1, then I think your best bet is to submit a patch through the <a class="ext-link" href="http://www.haskell.org/haskellwiki/Library_submissions"><span class="icon"></span>library submissions</a> process.
</p>
TicketpatperryFri, 22 Aug 2008 04:13:00 GMTattachment set
http://ghc.haskell.org/trac/ghc/ticket/2065
http://ghc.haskell.org/trac/ghc/ticket/2065
<ul>
<li><strong>attachment</strong>
set to <em>variant-bug.patch</em>
</li>
</ul>
<p>
Patch that fixes the bug
</p>
TicketsimonmarTue, 30 Sep 2008 15:45:16 GMTarchitecture changed
http://ghc.haskell.org/trac/ghc/ticket/2065#comment:2
http://ghc.haskell.org/trac/ghc/ticket/2065#comment:2
<ul>
<li><strong>architecture</strong>
changed from <em>Multiple</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketsimonmarTue, 30 Sep 2008 15:54:53 GMTos changed
http://ghc.haskell.org/trac/ghc/ticket/2065#comment:3
http://ghc.haskell.org/trac/ghc/ticket/2065#comment:3
<ul>
<li><strong>os</strong>
changed from <em>Multiple</em> to <em>Unknown/Multiple</em>
</li>
</ul>
Ticket