A Type-theoretic Reconstruction of the Visitor Pattern

  • Authors:
  • Peter Buchlovsky;Hayo Thielecke

  • Affiliations:
  • Computer Laboratory, University of Cambridge, Cambridge CB3 0FD, United Kingdom;School of Computer Science, University of Birmingham, Birmingham B15 2TT, United Kingdom

  • Venue:
  • Electronic Notes in Theoretical Computer Science (ENTCS)
  • Year:
  • 2006

Quantified Score

Hi-index 0.00

Visualization

Abstract

In object-oriented languages, the Visitor pattern can be used to traverse tree-like data structures: a visitor object contains some operations, and the data structure objects allow themselves to be traversed by accepting visitors. In the polymorphic lambda calculus (System F), tree-like data structures can be encoded as polymorphic higher-order functions. In this paper, we reconstruct the Visitor pattern from the polymorphic encoding by way of generics in Java. We sketch how the quantified types in the polymorphic encoding can guide reasoning about visitors in general.