Skip to content

Traits/interfaces #223

@SheepTester

Description

@SheepTester

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions