module test; import stdlib/io; fun main -> { io.println(foo() + 10); } trait Expr { visit(visitor: Visitor): T; } trait ExprVisitor { visitString(string: String): T; } trait List { size: int; get(index: int): T; set(index: int, value: T): void; } struct LinkedList { head: T?; tail: LinkedList?; init -> { self.head = null; self.tail = null; } } impl List for LinkedList { size -> { if self.head == null { return 0; } if self.tail == null { return 1; } return 1 + self.tail.size(); } get(index) -> { if index == 0 { return self.head; } return self.tail.get(index - 1); } set(index, value) -> { if index == 0 { self.head = value; return; } if self.tail == null { raise StringError( "LinkedList.set(...): index out of bounds", ); } self.tail.set(index - 1, value,); } } fun foo -> "Hello World!";