nick8325 / nick8325/quickcheck

Set modifiers of a function

Open
#205 0 comments 1 reaction 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

Here's an interesting construct to handle the modifiers that change generator behavior.

We have some property that we want to quickcheck

prop :: Int -> String -> (Int -> Int) -> Bool

but before that we'd like to use some modifiers, maybe to improve performance (e.g., Small), maybe to make the property Testable in the first place (e.g., Fun).

Current practice

One way is to integrate the modifiers into the type of prop.

prop :: Positive Int -> Small String -> Fun Int Int -> Bool

Another common way is to just write a lambda.

quickCheck $ \(Positive n) (Small s) (Fn f) -> prop n s f

New option

Assuming we don't want to mangle the type of prop, and we want to avoid listing the arguments twice (quite subjective expectations), we can look for combinators so we can use pointfree style. I found (Data.Function.&) and Data.Profunctor.dimap to fit nicely here.

quickCheck $ prop & (dimap getPositive $ dimap getSmall $ dimap apply $ id)

-- Just a reminder

dimap :: (c -> a) -> (b -> d) -> (a -> b) -> (c -> d)
      :: (Positive Int -> Int) -> ((String -> ...) -> (Small String -> ...)) -> (Int -> (String -> ...)) -> (Positive Int -> (Small String -> ...))

(&) :: p -> (p -> q) -> q

It might look nicer after refactoring dimap _ $ with more specialized infix combinators, something like this:

quickCheck $ prop & getPositive >? getSmall >! apply

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 issue's examples of Positive, Small, and Fun modifiers and the suggested (&) and dimap compositions. The issue names no files or tests; first identify the existing modifier APIs and test coverage, then determine whether a new combinator design is wanted and how its behavior would be validated.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
testing-qa
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.