"read: no parse" with functionShow

Brent Yorgey byorgey at seas.upenn.edu
Tue Jul 24 14:19:26 BST 2012


On Tue, Jul 24, 2012 at 01:17:29PM +0100, Nick Smallbone wrote:
> Hi Brent,
> 
> > But I still sometimes get a
> > "read: no parse" error.  Here is an excerpt from some output:
> >
> >   process/keepDelimsL match               *** Failed! Falsifiable (after 22 tests and 3 shrinks):
> >   Exception thrown by generator: 'Prelude.read: no parse'
> >   NonEmpty {getNonEmpty = [Elt {unElt = 'c'},Elt {unElt = 'c'},Elt {unElt = 'b'},Elt {unElt = 'a'},Elt {unElt = 'a'},Elt {unElt = 'd'}]}
> >
> > (Note that I expect a test failure; I deliberately introduced a bug.)
> > The property in question takes two arguments, Splitter Elt and
> > NonEmptyList Elt.  A Splitter Elt has several fields, one of which is
> > a Delimiter Elt, which is defined by
> >
> >   newtype Delimiter a = Delimiter [a -> Bool]
> >
> > and has an Arbitrary instance given by
> >
> >   instance (Arbitrary a, CoArbitrary a, Function a) => Arbitrary (Delimiter a) where
> >     arbitrary = (Delimiter . map apply) <$> arbitrary
> >
> > i.e. it generates an arbitrary list [Fun Elt Bool] using the Function
> > Elt instance, then converts it to an actual [Elt -> Bool] list.
> > Should this work?  Am I doing something wrong here?  I'm happy to send
> > you more info/a link to the repo if it would help.
> 
> Do you also shrink the functions in your Arbitrary instance? Shrinking
> is what turns the function into a finite, showable function, and also
> what turns it into a total function in this case.

No, I haven't overridden the definition of shrink in any of my custom
Arbitrary instances.  The only shrinks that are getting called are
ones in instances defined by QuickCheck.

-Brent



More information about the QuickCheck mailing list