Homogeneous types of selected arithmetic operators#330
Homogeneous types of selected arithmetic operators#330
Conversation
This commit changes types of additive, comparison, and bitwise operators to more homogeneous. Homogeneous types are more restrictive, but works better with type reconstruction. Multiplicative and bit-shift operators are left heterogeneous, because there are cases where it is useful (e.g., function composition or file path extending). Fixes #316
There was a problem hiding this comment.
Pull request overview
This PR updates the standard library operator definitions in Base/Operators to use more homogeneous (same-operand-type) signatures for selected arithmetic, comparison, and bitwise operators, aiming to improve type reconstruction (per issue #316).
Changes:
- Make
+,-, unary(- .),==,!=,<,<=,>,>=, and bitwise&&&,^^^,|||use homogeneous operand types. - Update these operator method constraints to return
T(or accept aTright-hand operand) rather than a separateUin several cases. - Introduce explicit effect annotations (
->[E]) into more of these operator constraints.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pub let (+) {method add : T -> T ->[E] T} (x : T) = x.add | ||
| pub let (-) {method sub : T -> T ->[E] T} (x : T) = x.sub |
There was a problem hiding this comment.
This PR is intended to improve type reconstruction for arithmetic/comparison operators, but there doesn’t appear to be a regression test capturing the motivating example (e.g., let f x = x + 1 typechecks without extra annotations). Adding an ok test (or stdlib test) for this inference case would help prevent future changes from reintroducing the issue.
There was a problem hiding this comment.
I agree. However, it is not clear to me, where should I put the test. Tests in the ok directory check general implementation, while the stdlib checks specific functions in the standard library.
This commit changes types of additive, comparison, and bitwise operators to more homogeneous. Homogeneous types are more restrictive, but works better with type reconstruction. Multiplicative and bit-shift operators are left heterogeneous, because there are cases where it is useful (e.g., function composition or file path extending).
Fixes #316