-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add sum() to List and Array #36
Conversation
math/algebraic.mbt
Outdated
/// Trait for types that override the `+` add operator. | ||
pub trait Add { | ||
op_add(Self, Self) -> Self | ||
} | ||
|
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.
I kinda feel this doesn't belong here, but I couldn't find an existing Add trait or a better place to put it.
is providing |
IMO we should provide such utility based on some general function and traits.
The implementation of |
what's the status of this PR? |
I just rebased this PR, but I don't have enough knowledge to mark it ready, please see my comments below.
It's mostly a question for the owners - how "battery-included" do we want to make the stdlib? I believe
I agree, quoting myself: "it seems like a better abstraction if we instead put it on an iterator (like Rust), only that we don't have iterators yet". However, I have some different opinions towards adding the
Compilation fails:
So basically, I'm proposing that we tear down the
This doesn't seem like a question for me, but my two cents for this is a mild "no" based on my limited FP knowledge and heavy Python background. I prefer the Rust-style combinators in a general iterator interface available over most sequential data structures. Examples would be the Actually, this is part of a bigger design question about how we want to organize the "duplicate" code where we have a separate Perhaps the long-awaited generic trait would solve this issue without introducing heavy logistics to get it going. Presumably, a general
To summarize, I'm not sure about the next steps. We have several options, and I'll be happy to create PRs once we decide on the direction(s):
|
@@ -2,6 +2,8 @@ | |||
"import": [ | |||
"moonbitlang/core/assertion", | |||
"moonbitlang/core/math", | |||
"moonbitlang/core/num", | |||
"moonbitlang/core/int", |
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.
int
should be a test_import
only.
The generic trait seems like a great solution. Now a lot of places can't go without it. |
Feels like this is the path we're going down now, so I'll close this PR in favor of adding
And to add the generic trait is still appreciated ✌️ |
Depends on@math
package added in Add@math.maximum()
and@math.minimum()
#35Num
trait #49I'm not sure if we even want the
sum()
functions directly on data structures, it seems like a better abstraction if we instead put it on an iterator (like Rust), only that we don't have iterators yet. So for testing/early-adopting purposes, I think it's fine to have them as demonstrated in this PR, even if it means we need to deprecate and remove them later.Ported from muts.