Iterators: signs of weakness in object-oriented languages

The appearance of iterators in an object-oriented language appears to be inversely related to the power of the language's intrinsic control structures. Iterator classes are used for the sole purpose of enumerating the elements of an abstract collection class without revealing its implementation. We find that the availability of higher-order functions and function closures eliminates the need for these ad hoc iterator classes, in addition to providing the other benefits of "mostly functional programming". We examine a purely functional iteration protocol for the difficult task of comparing the collections of leaves on two non-isomorphic trees---the so-called "samefringe" problem---and find that its type signature requires recursive (cyclic) functional types. Although higher-order "member functions" and recursive (cyclic) functional types are unusual in object-oriented languages, they arise quite naturally and provide a satisfying programming style.

[1]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[2]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[3]  Jr. Guy L. Steele,et al.  Common LISP: the language (2nd ed.) , 1990 .

[4]  Jr. Guy L. Steele,et al.  Rabbit: A Compiler for Scheme , 1978 .

[5]  Daniel P. Friedman,et al.  CONS Should Not Evaluate its Arguments , 1976, ICALP.

[6]  Ellis S. Cohen Updating elements of a collection in place , 1986, ALET.

[7]  Richard P. Gabriel The why of Y , 1988, LIPO.

[8]  Juris Hartmanis,et al.  The Programming Language Ada Reference Manual American National Standards Institute, Inc. ANSI/MIL-STD-1815A-1983 , 1983, Lecture Notes in Computer Science.

[9]  Henry Ledgard,et al.  Reference Manual for the ADA® Programming Language , 1983, Springer New York.

[10]  Craig Schaffert,et al.  Abstraction mechanisms in CLU , 1977, Commun. ACM.

[11]  D. H. Bartley,et al.  Revised4 report on the algorithmic language scheme , 1991, LIPO.

[12]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[13]  Craig Schaffert,et al.  CLU Reference Manual , 1984, Lecture Notes in Computer Science.

[14]  Mary Shaw,et al.  Abstraction and verification in Alphard: Defining and specifying iteration and generators , 1977 .

[15]  Henry G. Baker,et al.  Structured programming with limited private types in Ada: nesting if for the soaring eagles , 1991, ALET.

[16]  Henk Barendregt,et al.  The Lambda Calculus: Its Syntax and Semantics , 1985 .

[17]  Henry G. Baker,et al.  CONS should not CONS its arguments, or, a lazy alloc is a smart alloc , 1992, SIGP.

[18]  簡聰富,et al.  物件導向軟體之架構(Object-Oriented Software Construction)探討 , 1989 .

[19]  Christopher Coyle,et al.  Building abstract iterators using continuations , 1991, SIGP.