E4077#
Don't know how to derive trait for type.
MoonBit allows you to derive implementation of some pre-defined traits for your types. It means that you cannot have MoonBit automatically derive a trait that you defined yourself.
Erroneous example#
///|
trait T {
f(Self) -> Int
}
///|
struct A(Int) derive(T) // Error: Don't know how to derive trait T for type A
Suggestion#
You can implement the trait manually:
///|
priv trait T {
f(Self) -> Int
}
///|
priv struct A(Int)
///|
impl T for A with f(self : A) -> Int {
self.0
}
///|
test {
let value : A = A(1)
inspect(value.f(), content="1")
}