Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operators for generic n-ary product shrinking #3004

Conversation

jonathanknowles
Copy link
Contributor

Issue Number

#2999

Summary

This PR provides operators to make it easier to use generic n-ary product shrinking.

These operators allow us to compose shrinkers with a syntax that is very
similar to the applicative syntax for composing generators. This makes it easier to compare the definitions of generators and shrinkers that are related to one another.

For example:

data MyRecord = MyRecord
    { foo :: Foo
    , bar :: Bar
    , baz :: Baz
    }
    deriving (Eq, Generic, Show)

genMyRecord :: Gen MyRecord
genMyRecord = MyRecord
    <$> genFoo
    <*> genBar
    <*> genBaz

shrinkMyRecord :: MyRecord -> [MyRecord]
shrinkMyRecord = genericRoundRobinShrink
    <@> shrinkFoo
    <:> shrinkBar
    <:> shrinkBaz
    <:> Nil

Use  4n    space indents for expressions.
Use (4n+2) space indents for `where` clauses.
These operators allow us to define shrinkers with a syntax that is very
similar to the applicative syntax for defining generators.

For example:

```haskell

genMyRecord :: Gen MyRecord
genMyRecord = MyRecord
    <$> genFoo
    <*> genBar
    <*> genBaz

shrinkMyRecord :: MyRecord -> [MyRecord]
shrinkMyRecord = genericRoundRobinShrink
    <@> shrinkFoo
    <:> shrinkBar
    <:> shrinkBaz
    <:> Nil

```
Copy link
Contributor

@sevanspowell sevanspowell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@jonathanknowles jonathanknowles merged commit 40b9745 into feature/generics-sop-reduce-boilerplate Nov 8, 2021
@jonathanknowles jonathanknowles deleted the jonathanknowles/feature/generics-sop-reduce-boilerplate branch November 8, 2021 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants