-
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
Derive arithmetic operations for {Coin,TokenQuantity}
.
#3970
Derive arithmetic operations for {Coin,TokenQuantity}
.
#3970
Conversation
{Coin,TokenQuantity}
with monoid-subclasses
.{Coin,TokenQuantity}
with monoid-subclasses
.
{Coin,TokenQuantity}
with monoid-subclasses
.{Coin,TokenQuantity}
.
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.
lgtm!
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 |
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 serious :-)
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.
For this PR, the classes we care about are primarily:
MonoidNull
: provides thenull
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.)
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.
👍
Build succeeded: |
…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
Summary
This PR uses classes defined by the
monoid-subclasses
library to derive the definitions of all arithmetic operations for theCoin
andTokenQuantity
types.This takes advantage of the fact that both
Coin
andTokenQuantity
haveSemigroup
andMonoid
instances that are identical to those forSum Natural
.