Traits
This commit is contained in:
@@ -1,41 +1,39 @@
|
||||
namespace main
|
||||
|
||||
struct Name
|
||||
struct name
|
||||
{
|
||||
first: cstring
|
||||
last: cstring
|
||||
}
|
||||
|
||||
struct Human
|
||||
struct human
|
||||
{
|
||||
name: Name
|
||||
name: name
|
||||
age: i64
|
||||
}
|
||||
|
||||
interface Printable
|
||||
trait printable
|
||||
{
|
||||
func print()
|
||||
}
|
||||
|
||||
impl Human : Printable
|
||||
impl printable for human
|
||||
{
|
||||
func print() {
|
||||
c::puts(this.name)
|
||||
c::puts(this.name.first)
|
||||
}
|
||||
}
|
||||
|
||||
export func main(args: []cstring): i64
|
||||
{
|
||||
let x = alloc Human
|
||||
let human = alloc human
|
||||
{
|
||||
name = alloc Name {
|
||||
name = alloc name {
|
||||
first = "john"
|
||||
last = "doe"
|
||||
}
|
||||
age = 23
|
||||
}
|
||||
|
||||
x.print()
|
||||
human.print()
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user