-
Notifications
You must be signed in to change notification settings - Fork 217
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
Reduce boilerplate needed to use liftShrink
functions.
#2998
Merged
iohk-bors
merged 3 commits into
master
from
jonathanknowles/generalize-liftShrink-functions
Nov 3, 2021
Merged
Reduce boilerplate needed to use liftShrink
functions.
#2998
iohk-bors
merged 3 commits into
master
from
jonathanknowles/generalize-liftShrink-functions
Nov 3, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This module contains generic functions and types relating to data types with one or more fields.
In this commit, we generalize the `liftShrink` family of functions so that each of these functions can be applied to any data type with the right number of fields.
jonathanknowles
force-pushed
the
jonathanknowles/generalize-liftShrink-functions
branch
from
November 3, 2021 03:30
42c70d4
to
b65a698
Compare
jonathanknowles
force-pushed
the
jonathanknowles/generalize-liftShrink-functions
branch
from
November 3, 2021 03:35
db76309
to
b5ea488
Compare
sevanspowell
approved these changes
Nov 3, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like an improvement 👍
bors r+ |
iohk-bors bot
added a commit
that referenced
this pull request
Nov 3, 2021
2998: Reduce boilerplate needed to use `liftShrink` functions. r=jonathanknowles a=jonathanknowles ## Issue Number None ## Background Our `test-utils` package currently provides the `liftShrink` family of functions, which make it possible to write shrinkers in a compositional style. These functions are especially useful when defining shrinkers for record types: if you already have a shrinker for each of the fields, then you can build a shrinker for record values by composing the individual shrinkers with an appropriate `liftShrink`. However, when using these functions to shrink records, callers currently have to define boilerplate functions to convert between records and tuples. ## Summary This PR removes the need to define boilerplate tuple conversion functions. For example, we can make the following simplification: ```patch shrinkSelectionParams :: SelectionParams -> [SelectionParams] shrinkSelectionParams = - shrinkMapBy ofTuple toTuple $ liftShrink9 + liftShrink9 SelectionParams shrinkAssetsToBurn shrinkAssetsToMint shrinkOutputsToCover shrinkRewardWithdrawal shrinkCertificateDepositsTaken shrinkCertificateDepositsReturned shrinkCollateralRequirement shrinkUTxOAvailableForCollateral shrinkUTxOAvailableForInputs - where - toTuple (SelectionParams a b c d e f g h i) = (a, b, c, d, e, f, g, h, i) - ofTuple (a, b, c, d, e, f, g, h, i) = (SelectionParams a b c d e f g h i) ``` Co-authored-by: Jonathan Knowles <[email protected]>
Build failed: Failures:
src/Test/Integration/Scenario/CLI/Shelley/Transactions.hs:243:59:
1) CLI Specifications, SHELLEY_CLI_TRANSACTIONS, TRANS_CREATE_06 - Invalid amount, string with diacritics
uncaught exception: IOException of type ResourceVanished
fd:155: hFlush: resource vanished (Broken pipe) |
bors r+ |
Build succeeded: |
iohk-bors
bot
deleted the
jonathanknowles/generalize-liftShrink-functions
branch
November 3, 2021 05:31
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Number
None
Background
Our
test-utils
package currently provides theliftShrink
family of functions, which make it possible to write shrinkers in a compositional style.These functions are especially useful when defining shrinkers for record types: if you already have a shrinker for each of the fields, then you can build a shrinker for record values by composing the individual shrinkers with an appropriate
liftShrink
.However, when using these functions to shrink records, callers currently have to define boilerplate functions to convert between records and tuples.
Summary
This PR removes the need to define boilerplate tuple conversion functions.
For example, we can make the following simplification: