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

Implement Add on Option types #5328

Closed
wants to merge 1 commit into from
Closed

Conversation

bstrie
Copy link
Contributor

@bstrie bstrie commented Mar 12, 2013

This will allow you to use the + operator to add together any two
Options, assuming that the contents of each Option likewise implement
+. So Some(4) + Some(1) == Some(5), and adding with None leaves the
other value unchanged.

This might be monoidic? I don't know what that word means!

This will allow you to use the + operator to add together any two
Options, assuming that the contents of each Option likewise implement
+. So Some(4) + Some(1) == Some(5), and adding with None leaves the
other value unchanged.

This might be monoidic? I don't know what that word means!
@thestinger
Copy link
Contributor

I don't think this should require Copy, perhaps calling the add method would allow working around that?

@graydon
Copy link
Contributor

graydon commented Mar 12, 2013

I think this should work with any binop-with-an-identity

(which, wikipedia tells me, is almost a monoid! I don't know whether associativity is a relevant dimension of trying to generalize this. I would, for the sake of not scaring off readers, prefer we not wind up with something called "monoid" in the library)

@bstrie
Copy link
Contributor Author

bstrie commented Mar 12, 2013

@thestinger Yes, I initially tried without the Copy bound and it yelled at me. I'd be happy to forgo it if there's a better solution.

bors added a commit that referenced this pull request Mar 12, 2013
This will allow you to use the `+` operator to add together any two
Options, assuming that the contents of each Option likewise implement
`+`. So Some(4) + Some(1) == Some(5), and adding with None leaves the
other value unchanged.

This might be monoidic? I don't know what that word means!
@bors bors closed this Mar 12, 2013
@kud1ing
Copy link

kud1ing commented Mar 12, 2013

Can we now go on and make Option and Result a Monad? Just half kidding.

@sanxiyn
Copy link
Member

sanxiyn commented Mar 19, 2013

What about other operators?

@bstrie
Copy link
Contributor Author

bstrie commented Mar 19, 2013

@sanxiyn I'd need some guidance as to what that would mean. For example:

let foo = None;
let bar = Some(4);
let baz = foo - bar;  // what is baz?

The semantics are easy for addition. Not sure about the rest.

bors pushed a commit to rust-lang-ci/rust that referenced this pull request May 2, 2020
Also fixes the same for float_arithmetic.

changelog: integer_arithmetic,float_arithmetic: fix false negatives with references on integers

Fixes rust-lang#5328
bors added a commit to rust-lang-ci/rust that referenced this pull request May 2, 2020
…flip1995

integer_arithmetic: detect integer arithmetic on references.

changelog: integer_arithmetic fix false negatives with references on integers

Fixes rust-lang#5328
@zcesur zcesur mentioned this pull request Sep 1, 2020
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.

None yet

6 participants