class MyIterator { list: MyList<$0>; index: i64; fun next(self) -> $0 or nothing { if self.index < list.len() { let result = self.list[self.index]; self.index += 1; result } else { nothing } } } class MyList { list: list<$0>; fun get_iterator(self) -> MyIterator { new MyIterator { list: self.list, index: 0, } } } fun test() -> f64 { // Type needs to be inferred as MyList let x = MyList { list: [1, 2, 3] }; let sum = 0; for v in x { // Pick up the iterator methods sum = sum + v; } sum } // @ignore undesigned garbage, like all generics // @no-errors