Abstract

The ITERATOR pattern gives a clean interface for element-by-element access to a collection. Imperative iterations using the pattern have two simultaneous aspects: mapping and accumulating . Various existing functional iterations model one or other of these, but not both simultaneously. We argue that McBride and Paterson’s idioms , and in particular the corresponding traverse operator, do exactly this, and therefore capture the essence of the ITERATOR pattern. We present some axioms for traversal, and illustrate with a simple example, the repmin problem.

Highlights

  • Perhaps the most familiar of the so-called Gang of Four design patterns [5] is the ITERATOR pattern, which ‘provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation’

  • Monadic maps are very close to the idiomatic traversals that we propose as the essence of imperative iterations; for monadic idioms, traversal reduces exactly to monadic map

  • We have argued that idiomatic traversals capture the essence of imperative loops — both mapping and accumulating aspects

Read more

Summary

INTRODUCTION

Perhaps the most familiar of the so-called Gang of Four design patterns [5] is the ITERATOR pattern, which ‘provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation’ This is achieved by identifying an ITERATOR interface (for example, presenting operations to initialize an iteration, to access the current element, to advance to the element, and to test for completion), that collection objects are expected to implement — perhaps indirectly, via a subobject. C# has some syntactic sugar (matched in Java in version 1.5) to avoid the need to write the boilerplate code to manage an iteration over collection elements; we show an example below This makes code cleaner and simpler, but gives privileged status to the specific iteration interface chosen, and entangles the language and its libraries.

FUNCTIONAL ITERATION
Origami
Monadic Map
IDIOMS
Monadic Idioms
Naperian Idioms
Monoidal Idioms
Combining Idioms
Idiomatic Traversal
Shape and Contents
Collection and Dispersal
Backwards Traversal
LAWS OF TRAVERSE
Free Theorems
Composition
Naturality
Composition of Monadic Traversals
No Duplication
EXAMPLE
CONCLUSIONS
Full Text
Paper version not known

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.