struct list {
value: string;
next: list|void;
}
fun empty() {
return null as list|void
}
fun cons(v: string, l: list|void) {
make list(value:v, next:l) as list|void
}
main = fun() {
l = cons("first", cons("second", cons("third", empty())));
h = l;
next = empty();
/*
* Note that we cannot say "h = h.next" in the following loop,
* as inside the typecase, h has a different type from h.next.
* So we do the next best thing. (Pun not intended.)
*/
while true {
typecase h is void { break; }
typecase h is list {
print(h.value);
next = h.next;
}
h = next;
}
}