[Haskell-cafe] Need advise with using Quickcheck

Ruben Astudillo ruben.astud at gmail.com
Fri Jun 11 21:31:28 UTC 2021

Hello Han

On 11-06-21 17:16, Han Joosten wrote:
> [..]
> *parseFoo :: Text -> Guarded Foo*
> *prettyFoo :: Foo -> Text*
> The idea is that for all foo :: Foo, the following holds:
>     *parseFoo . prettyFoo $ foo*  should be equal to  *Checked foo []*
> Now, if there is a counterexample, I would like to see prettyFoo foo as
> output, folowed by the show of the Errors part.

It seems you know what property should hold for `parseFoo` and `prettyFoo`.
Per the QuickCheck manual [1] this could be written as

    import Test.QuickCheck

    propOnAllFooText :: Property
    propOnAllFooText = forAll (arbitrary :: Gen Foo) $ \exFoo ->
        parseFoo (prettyFoo exFoo) == Checked exFoo []

What you are missing is a way to generate the test cases (the `arbitrary'
generator above). You need a way to declare this instance

    instance Arbitrary Foo where
        -- arbitrary :: Gen Foo
        arbitrary = <something>

You can see example on how to define it on the manual [1]. Good luck.

[1]: http://www.cse.chalmers.se/~rjmh/QuickCheck/manual.html

-- Rubén
-- pgp: 4EE9 28F7 932E F4AD

More information about the Haskell-Cafe mailing list