[m-dev.] for review: quickcheck user guide

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Feb 12 23:05:46 AEDT 2001


On 12-Feb-2001, Mark Anthony BROWN <dougl at cs.mu.OZ.AU> wrote:
> Xiao Chun Simon MEI writes:
> > +:- module use1.
> > +
> > +:- interface.
> > +
> > +:- use_module io.
> > +
> > +:- pred main(io__state, io__state).
> > +:- mode main(di, uo) is det.
> > +
> > +%-------------------------------------------------------------------%
> > +
> > +:- implementation.
> > +
> > +:- import_module int, list.
> > +:- import_module qcheck, testrev2.
> > +
> > +%-------------------------------------------------------------------%
> > +
> > +main -->
> > +     	qcheck(qcheck__f(testing2), "testing2").
> > +
> > +%-------------------------------------------------------------------%
> > +% 	Invariant test functions
> > +%-------------------------------------------------------------------%
> > +
> > +:- func testing2(list(int), list(int)) = property.
> > +testing2(Xs, Ys) = (Left `===` Right) :-
> > +	testrev2((Xs ++ Ys), Left),
> > +	testrev2(Ys, Part_a),
> > +	testrev2(Xs, Part_b),
> > +	Right = Part_a ++ Part_b.
...
> > +An alternative to write use.m which does not evolving writing a separate 
> > +invariant function, (use11.m):
...
> > +:- module use11.
> > +
> > +:- interface.
> > +
> > +:- use_module io.
> > +
> > +:- pred main(io__state, io__state).
> > +:- mode main(di, uo) is det.
> > +
> > +%--------------------------------------------------------------------------%
> > +
> > +:- implementation.
> > +
> > +:- import_module int, list.
> > +:- import_module qcheck, testrev.
> > +
> > +%--------------------------------------------------------------------------%
> > +
> > +main -->
> > +    qcheck(qcheck__f(func(Xs `with_type` list(int), Ys `with_type` list(int))
> > +		     = testrev(Xs ++ Ys) `===` (testrev(Ys) ++ testrev(Xs))),
> > +           "sample testing").
> > +</pre></tr></table>
> 
> This is a fairly normal use of higher order code, and probably doesn't
> need its own example.

I disagree here; I think it's worth showing the higher-order code as
well, to encourage people to use a higher-order style when
appropriate.  But the original code is probably easier to understand
on a first reading, so IMHO both examples should stay.

In fact there is one fairly subtle point about the higher-order example,
namely the use of `with_type`.  The tutorial should explain why that
is needed.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list