Open bfrk opened 4 years ago
Fair enough. I'll try to work on a LeanCheck sub-module to allow Monadic style generators.
Yes. I am using leancheck's operations on tiers for (something like) "fair" logic programming (breadth first traversal of search space, instead of Prolog-like leftmost traversal)
interface: https://gitlab.imn.htwk-leipzig.de/waldmann/pure-matchbox/-/blob/master/src/Stream/Tiers.hs (the Monad instance is the same as in this issue here?)
application: https://gitlab.imn.htwk-leipzig.de/waldmann/pure-matchbox/-/blob/master/src/Matchbox/Transport.hs#L455
I find it peculiar that the monad here is not explicitly exposed, nor even mentioned in the docs. I currently have a module where I define it myself:
This allows me to much more easily define
Listable
instances using do-notation when the allowed elements of a certain data type depend on (and perhaps modify) some state. In my case, I have a state type and another data type representing changes to the state, and for changes to be valid they must be applicable to the current state.Having these instances also helps to convert existing QC
Arbitrary
instances toListable
, sinceTiers
corresponds exactly to QC'sGen
monad. In fact, if you don't use any special features ofGen
you may generalize your existing code to work with any given generator monad.Finally, note that this Monad instance is quite different from the one we get without the newtype wrapper (via the standard instance for lists). The latter is in fact quite useless.