-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: x/exp/constraints: move into math, sort #52427
Comments
I'm not sure that |
I think I think the math ones read fine though: |
Conversely, as I mentioned in #45458 (comment), constraints might not always remain only constraints. Committing to names like |
I think this is a good one to avoid the lengthy I have been experimenting with roughly the same idea that uses self-defined The key questions: do we really need a centralized place to define "all" constraints? or how many constraints are expected to appear but not yet in |
One addition but less problematic: the dependencies of |
Perhaps it's a coincidence that the current constaints can be considered for the This is hypothetical, but it's hard to predict where type parameters and constraints will evolve over time - developers have only started exploring this space. Is this mostly a workaround for |
I think experience is showing that you don't really need that many constraints, except for Ordered or (and this isn't in the exp/constraints anyway) byteseq. "Constraints" is like "utils" but for types. It's better to have something specific than a bunch of general stuff crammed in one place. |
The main problem with a constraints package is that is is very likely to become a dependency of all generic packages, even though it doesn't have any functionality, only types. But "a little copying is better than a little dependency", so it is probably better for each generic package to define its own constraints. |
|
@beoran It would be interesting to see how many packages that use generics do in fact import constraints. I would be surprised if most do. I checked some packages in Google internal code that define generics, and none of them import constraints. |
My team just went down the rabbit hole of history today trying to track down the new home of x/exp/slices.SortFunc (after discovering a major performance win from moving from sort.Slice to sort.Sort and wondering if a generic version of sort.Slice would've been faster), and if I'm reading the closed proposals correctly it seems like this issue is the current "blocker" for that functionality going into the standard library -- we need constraints.Ordered or sort.Ordered or something equivalent before we can get slices.Sort. Is that correct? If so, can we get an update on the status of this proposal? |
(Interesting that there wasn't already a link between these issues.) |
As long as we're cross-indexing: #59488 is for Much less officially, in #60274 (comment) there's an alternative to putting the numeric constraints in math. |
This is follow up to #50792.
Most of the remaining constraints after #48424 are purely numeric: Complex, Float, Integer, Signed, Unsigned. They can all just be added to package math. Ordered is the exception because it also involves strings. It can be added to package sort. There's no longer any need for a top level constraints package.
The text was updated successfully, but these errors were encountered: