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.
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.