Skip to content

New method system #5

@dominik-muc

Description

@dominik-muc

Instead of current approach, we could see methods on types as a kind of feature extension.
Let's separate them from the type declaration, because:

  • it allows to extend external types (for example coloring methods for strings)
  • it can group similar behavior
  • it allows for parameter-specific extensions (for example .product() on Vec<i32>)

The main issue that many languages, including Rust, suffers from, is that two independent
crates can implement the same methods/traits, resulting in conflicts. Rust prohibits this
by coherence rules, but I have a (maybe?) better idea — let the extensions be named.
A method is accessible if the name is imported by scope. If two, differently named
extensions add method with the same name, disambiguation is requested by the compiler.

I propose the following syntax:

ext <name> for <type> {
    <methods>
}

The question is whether to allow generic extensions (eg. ext<T> vec_impl for Vec<T>)

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfrontendRequires work with compiler frontendhelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions