Since Moonbit feels Rusty, curious to know if Moonbit aims to align with the following in the future or if the goal is actually not to do it due to particular reasons:
- In terms of syntax, it was really great to see the latest blog post that enables implementing traits explicitly:
impl Trait with method(...) { ... }
impl Trait for Type with method(...) { ... }
Does this mean this exists in parallel to interfaces being structural behind the scenes? So we have the choice between both the explicit syntax and the implicit one? (where a struct that has the right methods will automatically type check for this trait)
- (Minor syntax difference) explicit trait specification for multiple methods
// We will have to repeat `impl Trait with` for every default method
impl MyTrait with default_method(...) { ... }
impl MyTrait with default_method2(...) { ... }
// We will have to repeat each `impl MyTrait for Type with`
// And they are not enforced to be in the same block corresponding to a particular trait
impl MyTrait for Type with method1(...) { ... }
impl MyTrait for Type with method2(...) { ... }
impl MyTrait for Type with method3(...) { ... }
impl OtherTrait for Type with method1(...) { ... }
impl OtherTrait for Type with method2(...) { ... }
// We cannot write something like:
impl MyTrait for Type {
fn method1(...) { ... }
fn method2(...) { ... }
fn method3(...) { ... }
}
impl OtherTrait for Type {
fn method1(...) { ... }
fn method2(...) { ... }
}
=> Is there maybe a reason/advantage they need to be specified with additional blocks, repeating the impl Trait with/for
? Or is it possible that the syntax changes in the future?
- Multiple and custom attributes (like Rust’s
#[]
)
// Right now we have:
struct Point[N] {
x: N
y: N
} derive(Debug)
// Will we be able to have multiple attributes in the future?
// As well as custom ones when there is a macro system and any information on the vision planned for macros?
// For example will we be able to do in the future
#[derive(Debug, OtherAttribute)]
#[allow(unused_variables)]
#[my_custom_attribute]
struct Point[N] {
x: N
y: N
}