Skip to content

Instantly share code, notes, and snippets.

@tiye
Created June 14, 2024 17:48
Show Gist options
  • Save tiye/0c6cf300876a1df0b68f178037062ea3 to your computer and use it in GitHub Desktop.
Save tiye/0c6cf300876a1df0b68f178037062ea3 to your computer and use it in GitHub Desktop.
demonstrage dyn trait object demo in moonbit
trait Eff {
run(Self) -> Unit
}
struct A {
a: Int
} derive (Debug)
fn A::run(self: A)-> Unit {
println("DEMO")
}
struct B {
b: String
} derive (Debug)
fn B::run(self: B)->Unit {
println("DEMO")
}
struct Combined {
c: Array[Eff]
}
fn init {
let a = {a: 1}
let b ={b:"ccc"}
let c = {c: [a as Eff, b as Eff]}
debug(a)
debug(b)
debug(c.c.length())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment