"read: no parse" with functionShow
Nick Smallbone
nick.smallbone at gmail.com
Tue Jul 24 13:17:29 BST 2012
Hi Brent,
On 22 July 2012 15:01, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> Thanks for the response. It works *more often* for me now (though it
> seems to run two-three times slower).
Yes - I imagine that using functionShow isn't very fast in general.
> 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.
Nick
More information about the QuickCheck
mailing list