Computer Science Department
Programming Methods Laboratory

Theorie des Langages /
Fondements de la Programmation
Ecole Polytechnique Federale de Lausanne
Exercises
25.05.2K

We want to implement Iterators in Funnel. The following definition describes the abstract Iterator class:
    abstract class Iterator = {
        abstract def next
        abstract def hasNext
        def toList = ...
        def toString = ...
    }
A ListIterator inherits from Iterator and defines the two abstract methods next and hasNext:
    final class ListIterator(xs) extends Iterator = {
        def next = ...
        def hasNext = ...
    }
The ListIterator class is final, so subclassing should not be possible. Implement the Iterator and ListIterator classes in Funnel. Here's a framework:
import "List.fn"
import "Predef.fn"

type ConcreteIterator = (toList, toString)
type Iterator = (with ConcreteIterator, next, hasNext)

val Iterator = {
    ...
}

val ListIterator = {
    ...
}

// execute some example code
val xs = List.make5(2, 4, 6, 8, 9)
ListIterator.new(xs).toString