Iterators
- 1 July 1993
- journal article
- Published by Association for Computing Machinery (ACM) in ACM SIGPLAN OOPS Messenger
- Vol. 4 (3) , 18-25
- https://doi.org/10.1145/165507.165514
Abstract
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.Keywords
This publication has 6 references indexed in Scilit:
- A theory of type polymorphism in programmingPublished by Elsevier ,2003
- CONS should not CONS its arguments, or, a lazy alloc is a smart allocACM SIGPLAN Notices, 1992
- Structured programming with limited private types in AdaACM SIGAda Ada Letters, 1991
- The why of YACM SIGPLAN Lisp Pointers, 1988
- Revised 3 report on the algorithmic language schemeACM SIGPLAN Notices, 1986
- Updating elements of a collection in placeACM SIGAda Ada Letters, 1986