trait Talkable:
fn hello(self, thing: Talkable) -> String: ...
fn goodbye(self, thing: Talkable) -> String: ...
fn get_name(self) -> String: ...
struct Person(Talkable):
var name: String
fn __init__(inout self, name: String):
self.name = name
fn hello(self, thing: Talkable) -> String:
return self.name + " says hello to " + thing.get_name()
fn goodbye(self, thing: Talkable) -> String:
return self.name + " says goodbye to " + thing.get_name()
fn get_name(self) -> String:
return self.name
struct Dog(Talkable):
var value: __mlir_type
var name: String
var nick_name: String
var age: Int
fn __init__(inout self, name: String, nick_name: String, age: Int):
self.name = name
self.nick_name = nick_name
self.age = age
fn hello(self, thing: Talkable) -> String:
return self.name + " barks at " + thing.get_name()
fn goodbye(self, thing: Talkable) -> String:
return self.name + " barks at " + thing.get_name()
fn get_name(self) -> String:
return self.name
# I also tried this from documentation
# fn say_hello[T: Talkable](t1: T, t2: T):
# t1.hello(t2)
fn main():
var s = Person(name="Jim")
var d = Dog("spot", "dog", 2)
d.hello(s)
# say_hello(s, d)