E4077

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  {
  () -> 
}

///|
priv struct ()

///|
impl  for  with ( : ) ->  {
  .0
}

///|
test {
  let  :  = (1)
  (.(), ="1")
}