qcheck icon indicating copy to clipboard operation
qcheck copied to clipboard

Provide a more generic combinator (similar to Crowbar `gens`)

Open sir4ur0n opened this issue 4 years ago • 1 comments

(This should be my last issue in the foreseeable future :grin: )

Currently QCheck provides pair, triple and quad to combine arbitraries into tuples, and then Test.make takes a single arbitrary to write the test.

So if one wants 3 ints, 3 strings and 3 bools, one must write one of the following:

Test.make (pair (pair (quad int int int string) (quad string string bool bool)) bool) (fun (((i1, i2, i3, s1), (s2, s3, b1, b2), b3) -> ...)

Test.make (triple (triple (int int int) (triple string string string) (triple bool bool bool)) (fun ((i1, i2, i3), (s1, s2, s3), (b1, b2, b3) -> ...)

(* etc. *)

(Yes, 9 arguments is a bit extreme, but in my experience 5 or 6 happens, and the problems below occur even with a single pair)

This has several quality-of-life problems:

  • whenever a param needs to be added or removed, it is cumbersome to adapt the pairs/triples/quadruples in both the generator combination, and in the function arguments
  • it "forces" arbitrary (haha) grouping of arbitraries/arguments together
  • No currying (which also induces "no partial application")
  • This is verbose

Note that none of the problems above is a show stopper. This is purely about improving the dev experience.

One thing I really like in Crowbar is the flat list of generators, which solves both problems above, thanks to the gens type (recursive type wrapping together the generator of 'a and the function that consumes an 'a) and add_test.

With Crowbar the example above is written:

add_test [int; int; int; string; string; string; bool; bool; bool] (fun i1 i2 i3 s1 s2 s3 b1 b2 b3 -> ...)

Would such a thing be possible in QCheck?

If not, at least could we consider providing combinators up to 8, with less verbose names? E.g. t2/t3/t4/t5/t6/t7/t8 rather than pair/triple/quad/???. While this would not completely solve all the problems listed above, this would decrease verbosity.

Note: I saw the Tuple submodule but the only documentation that mentions it is about arbitrary functions, I'm not even sure this is usable for the need of this issue

sir4ur0n avatar Mar 16 '21 09:03 sir4ur0n

I just started working on a project where I'd like to have that kind of feature for generators. I'll let you know If I come up with something usable for QCheck.

edit: the type I'm using is exactly the one in Crowbar

vch9 avatar Jul 15 '21 18:07 vch9