nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
717 stars 119 forks source link

introduce `discardUnless` #374

Open MaximilianAlgehed opened 6 months ago

MaximilianAlgehed commented 6 months ago

Closes #363

The tricky thing here is the lazy behaviour of Gen and forAll. That's what makes me unsure whether or not suchThatDiscard is a good idea in practice.

nick8325 commented 6 months ago

What's the use case for this?

It's unfortunate that this has a similar name to suchThat and suchThatMaybe but behaves rather differently - in that it only tries the generator once but they retry until they succeed.

MaximilianAlgehed commented 6 months ago

I should clarify. I don't feel particularly strongly about this idea (and the name does suck, perhaps discardUnless would be better?) but I was hoping it might provide a nicer interface to discard for #363 but that's just an idea.

MaximilianAlgehed commented 6 months ago

I'll clarify some more. The problem raised by the issue is basically that unless (p a) discard >> pure a is a pitfall. Its clear what you intend but that is not what you get. By introducing a suchThat like thing you can express this intention in a natural way that does what you want.

We can have a separate conversation about what the role of discard is and whether or not its a good idea to use it in Gen but the problem raised by the issue is that since its there people are using it.

nick8325 commented 5 months ago

I must admit, I'm a bit sceptical that people will actually use this, just because I always find the suchThat API a bit clunky to use. But I've no objection to merging it.