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

Traits/interfaces #223

Open
SheepTester opened this issue Jul 16, 2021 · 0 comments
Open

Traits/interfaces #223

SheepTester opened this issue Jul 16, 2021 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@SheepTester
Copy link
Member

For operator overloading, I think we could be like Rust and define traits for each operation (addition, etc.). Then types (probably just enum types) can implement traits. Traits can also have default implementations for values, and they can be used as types.

For example,

// Will probably be pre-defined by N (ie built in)
trait Add[this] {
  add : this -> this -> this
}

type vec2 = <vec2 float float>

implement Add[vec2] {
  add = [<vec2 x1 y1>: vec2 <vec2 x2 y2>: vec2] -> vec2 {
    return (x1 + x2, y1 + y2)
  }
}

print(vec2(1, 2) + vec2(3, 4)) // vec2(3, 6)

This proposal needs more fleshing out before being implemented, hence "N Next"

@SheepTester SheepTester added this to the N Next milestone Jul 16, 2021
@SheepTester SheepTester added enhancement New feature or request help wanted Extra attention is needed labels Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant