Skip to content

Feature request: explicit implementation of trait for type #1133

Description

@tionway

Summary

To implement a trait for a type, it must use syntax like impl Trait for Type ... to specify it.

Motivation

To prevent unintended trait implementations and facilitate searching for a type's trait implementations.

Detailed Design

Always require a impl Trait for Type ... block when implementing trait.

Drawbacks

A programming language like Rust, which implements this feature, requires a complex trait solver and has encountered several bugs related to subtyping in lifetimes. Moonbit, without lifetimes, might not require such a complex implementation. However, adding this feature to Moonbit could still increase compiler complexity and reduce compilation speed.

Alternatives

For unintended trait implementations, Moonbit may require that type is not implemented for specific traits.
For searching implementations, hoping LSP of Moonbit could solve this erogonomic issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions