nick8325 / nick8325/quickcheck

RFC: Create a SuchThat data type that allows call site `suchThat`

Open
#215 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
790
Forks
130
Avg merge
16h 41m
Merged PRs (30d)
2

Description

I was recently writing tests where I needed some properties to hold in a specific situation. My usual path here is to make a newtype to get the Arbitrary instance I want. However I realized that suchThat could be used at the call site via Testable. What do you think of this type?

data SuchThat a prop = SuchThat (a -> Bool) (a -> prop)

instance (Arbitrary a, Show a, Testable prop) => Testable (SuchThat a prop) where
  property (SuchThat predicate prop) =
    forAllShrink (arbitrary `suchThat` predicate) shrink prop

This allows Arbitrary instances to be decorated via a generic combinator at the call site.

Here is a trivial example that would always pass:

it "is greater than 0" . property . SuchThat (> 0) $ \int -> int > 0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed SuchThat definition and its Testable instance in the issue, then inspect QuickCheck’s existing Testable, Arbitrary, and suchThat APIs. Because this is an RFC, clarify the desired API and acceptance criteria with maintainers before implementing; done would mean an agreed design and accompanying implementation and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.