enum Optional[T] {
Some(T)
None
}
fn map[A, B](self : Optional[A], f : (A) → B) → Optional[B] {
match self {
Some(x) => Some(f(x))
None => None
}
}
impl[T : Show] Show for Optional[T] with to_string(self : Optional[T]) → String {
match self {
Some(x) => “Some({x})”
None => “None”
}
}
fn main {
println(@lib.hello())
println(Some(1).map(fn(m) { m + 1 }))
}
impl[T : Show] Show for Optional[T]这句报错
Type Optional does not implement trait Show, although an impl
is defined. hint: method output is missing.(4063)
moon version
moon 0.1.20241028 (2c58176 2024-10-28)