2008-04-22 [長年日記]
λ. “The Essense of the Iterator Pattern” by Jeremy Gibbons and Bruno C. d. S. Oliveira
The Iterator pattern gives a clean interface for element-by-element access to a collection, independent of the collection's shape. Imperative iterations using the pattern have two simultaneous aspects: mapping and accumulating. Various existing functional models of iteration capture one or other of these aspects, but not both simultaneously. We argue that McBride and Paterson's applicative functors, and in particular the corresponding traverse operator, do exactly this, and therefore capture the essence of the Iterator pattern. Moreover, they do so in a way that nicely supports modular programming.We present some axioms for traversal, discuss modularity concerns, and illustrate with a simple example, the wordcount problem.
を読んだ。
Applicative Programming with Effects (c.f. ヒビルテ(2006-12-07)) の applicative functor を使ってイテレータパターンの本質を解き明かす。 HaskellのData.Traversableモジュール辺りはこの論文に基づいている。