Skip to content

Homogeneous types of selected arithmetic operators#330

Open
ppolesiuk wants to merge 1 commit intomasterfrom
316-homogeneous-operators
Open

Homogeneous types of selected arithmetic operators#330
ppolesiuk wants to merge 1 commit intomasterfrom
316-homogeneous-operators

Conversation

@ppolesiuk
Copy link
Member

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

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
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a T right-hand operand) rather than a separate U in 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.

Comment on lines +11 to +12
pub let (+) {method add : T -> T ->[E] T} (x : T) = x.add
pub let (-) {method sub : T -> T ->[E] T} (x : T) = x.sub
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

@wojpok wojpok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

Homogeneous types of arithmetic operators

3 participants