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

Derive arithmetic operations for {Coin,TokenQuantity}. #3970

Merged
merged 15 commits into from
May 31, 2023

Conversation

jonathanknowles
Copy link
Member

@jonathanknowles jonathanknowles commented May 31, 2023

Summary

This PR uses classes defined by the monoid-subclasses library to derive the definitions of all arithmetic operations for the Coin and TokenQuantity types.

This takes advantage of the fact that both Coin and TokenQuantity have Semigroup and Monoid instances that are identical to those for Sum Natural.

@jonathanknowles jonathanknowles changed the title Derive arithmetic operations on {Coin,TokenQuantity} with monoid-subclasses. Derive arithmetic operations for {Coin,TokenQuantity} with monoid-subclasses. May 31, 2023
@jonathanknowles jonathanknowles changed the title Derive arithmetic operations for {Coin,TokenQuantity} with monoid-subclasses. Derive arithmetic operations for {Coin,TokenQuantity}. May 31, 2023
Copy link
Member

@Anviking Anviking left a comment

Choose a reason for hiding this comment

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

lgtm!

@jonathanknowles jonathanknowles self-assigned this May 31, 2023
@jonathanknowles
Copy link
Member Author

bors r+

deriving (Commutative, Semigroup, Monoid, MonoidNull) via Sum Natural
deriving (LeftReductive, RightReductive, Reductive) via Sum Natural
deriving (LeftGCDMonoid, RightGCDMonoid, GCDMonoid) via Sum Natural
deriving (OverlappingGCDMonoid, Monus) via Sum Natural
Copy link
Contributor

Choose a reason for hiding this comment

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

looks serious :-)

Copy link
Member Author

@jonathanknowles jonathanknowles May 31, 2023

Choose a reason for hiding this comment

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

For this PR, the classes we care about are primarily:

  • MonoidNull: provides the null operation: null x == (x == mempty).
  • Reductive: provides the reductive subtraction operation: </> :: m -> m -> Maybe m (this is a partial inverse of <>).
  • Monus: provides the monus (truncated) subtraction operation: <\> :: m -> m -> m

The other classes are superclasses of the classes we're interested in, which means we must derive them too. (It would be nice if there was a way to auto-derive superclasses without explicitly listing them, but there isn't.)

Copy link
Contributor

@paweljakubas paweljakubas left a comment

Choose a reason for hiding this comment

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

👍

@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 31, 2023

Build succeeded:

@iohk-bors iohk-bors bot merged commit 8622cfd into master May 31, 2023
@iohk-bors iohk-bors bot deleted the jonathanknowles/simplify-Coin-TokenQuantity branch May 31, 2023 10:44
WilliamKingNoel-Bot pushed a commit that referenced this pull request May 31, 2023
…a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: CODE-OF-CONDUCT.md CODEOWNERS LICENSE README.md bors.toml cabal.project default.nix docker-compose.yml docs flake.lock flake.nix floskell.json hie-direnv.yaml lib nix prototypes reports scripts shell.nix specifications test touch.me.CI weeder.dhall Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. CODE-OF-CONDUCT.md CODEOWNERS LICENSE README.md bors.toml cabal.project default.nix docker-compose.yml docs flake.lock flake.nix floskell.json hie-direnv.yaml lib nix prototypes reports scripts shell.nix specifications test touch.me.CI weeder.dhall Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. CODE-OF-CONDUCT.md CODEOWNERS LICENSE README.md bors.toml cabal.project default.nix docker-compose.yml docs flake.lock flake.nix floskell.json hie-direnv.yaml lib nix prototypes reports scripts shell.nix specifications test touch.me.CI weeder.dhall Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> - [x] Added withdrawal support for multisig - [x] Added withdrawal integration test - [x] Added quit integration test - [x] Make sure getTransaction exposes certificates - shown in integration testing ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-2604
 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
 Note: Jira issues of the form ADP- will be auto-linked. -->
 3970: Derive arithmetic operations for `{Coin,TokenQuantity}`. r=jonathanknowles a=jonathanknowles ## Summary
 
 This PR uses classes defined by the [`monoid-subclasses`](https://hackage.haskell.org/package/monoid-subclasses-1.2.3#readme) library to derive the definitions of all arithmetic operations for the `Coin` and `TokenQuantity` types.
 
 This takes advantage of the fact that both `Coin` and `TokenQuantity` have `Semigroup` and `Monoid` instances that are identical to those for `Sum Natural`. Co-authored-by: Pawel Jakubas <[email protected]> Co-authored-by: Piotr Stachyra <[email protected]> Co-authored-by: Jonathan Knowles <[email protected]> Source commit: 8622cfd
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.

3 participants