gen.filter with discards (maxDiscards, Report.discarded) #9

Closed
opened 2026-09-13 21:24:23 +09:00 by natsukium · 1 comment
Owner

Missing

gen.filter pred g and a notion of discard in the runner (maxDiscards, Report.discarded).

Why

Every framework has a retrying filter (Hedgehog Gen.filter, QuickCheck suchThat, Hypothesis .filter, fast-check .filter). Without it callers hand-roll map tricks that distort the distribution. Two upcoming needs:

  • #4 gen.attrsOf: drop-duplicates is the fallback; retrying is what Hedgehog Gen.map does to hit the drawn size.
  • #3 gen.float: "edge values inside the range" is a filter.

Suggested shape

  • Hedgehog strategy: retry with the size bumped a little each attempt; give up after n tries and signal a discard.
  • Discard is a distinguished tree value (or null in an { ok; value } wrapper) the runner recognises; discarded cases do not count toward tests.
  • check takes maxDiscards (default ~ tests * 10 like QuickCheck's ratio) and reports discarded.
  • Shrinking must skip candidates the predicate rejects (Hedgehog filters the tree, Tree.filter).
## Missing `gen.filter pred g` and a notion of *discard* in the runner (`maxDiscards`, `Report.discarded`). ## Why Every framework has a retrying filter (Hedgehog `Gen.filter`, QuickCheck `suchThat`, Hypothesis `.filter`, fast-check `.filter`). Without it callers hand-roll `map` tricks that distort the distribution. Two upcoming needs: - #4 `gen.attrsOf`: drop-duplicates is the fallback; retrying is what Hedgehog `Gen.map` does to hit the drawn size. - #3 `gen.float`: "edge values inside the range" is a filter. ## Suggested shape - Hedgehog strategy: retry with the size bumped a little each attempt; give up after `n` tries and signal a discard. - Discard is a distinguished tree value (or `null` in an `{ ok; value }` wrapper) the runner recognises; discarded cases do not count toward `tests`. - `check` takes `maxDiscards` (default ~ `tests * 10` like QuickCheck's ratio) and reports `discarded`. - Shrinking must skip candidates the predicate rejects (Hedgehog filters the tree, `Tree.filter`).
Author
Owner

Implemented in c826d84, pushed to main.

Implemented in c826d84, pushed to main.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
natsukium/nixcheck#9
No description provided.