Skip to main content
Article
Patterns as Objects in Grace
ACM SIGPLAN Notices
  • Andrew P. Black, Portland State University
  • Michael Homer, Victoria University of Wellington
  • James Noble, Victoria University of Wellington
  • David J. Pearce, Victoria University of Wellington
  • Kim B. Bruce, Pomona College
Document Type
Conference Proceeding
Publication Date
1-1-2012
Subjects
  • Object-oriented languages (Computer program languages),
  • Object-oriented methods (Computer science)--Software,
  • Programming languages (Electronic computers)--Software
Abstract

Object orientation and pattern matching are often seen as conflicting approaches to program design. Object oriented programs place type-dependent behaviour inside objects and invoke it via dynamic dispatch, while pattern matching programs place type-dependent behaviour outside data structures and invoke it via multiway conditionals (case statements). Grace is a new, dynamic, object-oriented language designed to support teaching: to this end, Grace needs to support both styles. In this paper we explain how this conflict can be resolved gracefully: by modelling patterns and cases as partial functions, reifying those functions as first-class objects, and then building up complex patterns from simpler ones using pattern combinators. We describe our design for pattern matching in Grace, and its implementation as an object-oriented framework.

Description

© ACM, 2012. This is the author's version of the work. It is posted here by permission of ACM for your personal use. Not for redistribution. The definitive version was published in ACM SIGPLAN Notices. Vol. 48. No. 2. ACM,2012. http://doi.acm.org/10.1145/2384577.2384581

DOI
10.1145/2384577.2384581
Persistent Identifier
http://archives.pdx.edu/ds/psu/12084
Citation Information
Homer, Michael, et al. "Patterns as objects in Grace." ACM SIGPLAN Notices. Vol. 48. No. 2. ACM, 2012.