Created
June 14, 2024 17:48
-
-
Save tiye/0c6cf300876a1df0b68f178037062ea3 to your computer and use it in GitHub Desktop.
demonstrage dyn trait object demo in moonbit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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