article

Extensible pattern matching via a lightweight language extension

Published:01 October 2007Publication History

Abstract

Pattern matching of algebraic data types (ADTs) is a standard feature in typed functional programming languages, but it is well known that it interacts poorly with abstraction. While several partial solutions to this problem have been proposed, few have been implemented or used. This paper describes an extension to the .NET language F# called active patterns, which supports pattern matching over abstract representations of generic heterogeneous data such as XML and term structures, including where these are represented via object models in other .NET languages. Our design is the first to incorporate both ad hoc pattern matching functions for partial decompositions and "views" for total decompositions, and yet remains a simple and lightweight extension. We give a description of the language extension along with numerous motivating examples. Finally we describe how this feature would interact with other reasonable and related language extensions: existential types quantified at data discrimination tags, GADTs, and monadic generalizations of pattern matching.

References

  1. V. Benzaken, G. Castagna, and A. Frisch. CDuce: An XML-centric general purpose language. In Proceedings of 2003 ACM SIGPLAN International Conference on Functional Programming. ACM Press, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. F. Warren Burton and Robert D. Cameron. Pattern matching with abstract data types. Journal of Functional Programming, 3(2):171--190, 1993.Google ScholarGoogle ScholarCross RefCross Ref
  3. Burak Emir and Martin Odersky. Matching Objects with Patterns. In ECOOP '07, 2007. To appear. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Martin Erwig. Active patterns. In Implementation of Functional Languages. Springer, 1997.Google ScholarGoogle ScholarCross RefCross Ref
  5. Martin Erwig and Simon Peyton Jones. Pattern Guards and Transformational Patterns. In Haskell Workshop, 2000.Google ScholarGoogle Scholar
  6. Manuel Fähndrich and John Boyland. Statically checkable pattern abstractions. In International Conference on Functional Programming. ACM, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Pedro Palao Gostanza, Ricardo Pena, and Manuel Nunez. A new look at pattern matching in abstract data types. In ICFP '96: Proceedings of the first ACM SIGPLAN international conference on Functional programming, pages 110--121, New York, NY, USA, 1996. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Jim Grundy, Tom Melham, and John O'Leary. A reflective functional language for hardware design and theorem proving. Journal of Functional Programming, 16(2):157--196, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Tim Harris, Simon Marlow, Simon Peyton Jones, and Maurice Herlihy. Composable memory transactions. In Principles and Practice of Parallel Programming. ACM, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Haruo Hosoya and Benjamin Pierce. Regular expression pattern matching for XML. ACM SIGPLAN Notices, 36(3):67--80, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Martin Jambon. Micmatch. martin.jambon.free.fr/micmatch.html, 2007.Google ScholarGoogle Scholar
  12. Konstantin Läufer and Martin Odersky. An extension of ML with first class abstract types. In ACM SIGPLAN Workshop on ML and its Applications, San Francisco, California, pages 78--91, June 1992.Google ScholarGoogle Scholar
  13. Fabrice Le Fessant and Luc Maranget. Optimizing pattern-matching. In Proceedings of the 2001 International Conference on Functional Programming. ACM Press, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Luc Maranget. Warnings for pattern matching. Journal of Functional Programming, 17(3):647--656, 2007.Google ScholarGoogle ScholarCross RefCross Ref
  15. Erik Meijer and Brian Beckman. XLinq: XML Programming Refactored. research.microsoft.com/~emeijer, 2006.Google ScholarGoogle Scholar
  16. Nemerle. Nemerle website. nemerle.org, 2006.Google ScholarGoogle Scholar
  17. Martin Odersky. Scala website. scala.epfl.ch, 2006.Google ScholarGoogle Scholar
  18. Martin Odersky and Philip Wadler. Pizza into Java: Translating theory into practice. In Principles of Programming Languages. ACM, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Chris Okasaki. Views for Standard ML. In SIGPLAN Workshop on ML, Baltimore, Maryland, USA, pages 14--23, September 1998.Google ScholarGoogle Scholar
  20. Simon Peyton Jones. View patterns: lightweight views for Haskell (wiki entry). hackage.haskell.org/trac/ghc/wiki/ViewPatterns, 2007.Google ScholarGoogle Scholar
  21. Andreas Rossberg. Generalizing layered patterns to conjunctive patterns. successor-ml.org, 2007a. Search for "Generalizing Layered Patterns".Google ScholarGoogle Scholar
  22. Andreas Rossberg. Hamlet S: To Become or Not To Become SuccessorML. www.ps.uni-sb.de/hamlet/hamlet-succ-1.3.0S4.pdf, 2007b. Appendix B.17 and B.19.Google ScholarGoogle Scholar
  23. Kevin Scott and Norman Ramsey. When Do Match-compilation Heuristics Matter? Technical Report CS-2000-13, University of Virginia, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Don Syme. Active patterns in F#. blogs.msdn.com/dsyme, 2006a.Google ScholarGoogle Scholar
  25. Don Syme. Leveraging .NET meta-programming components from F#: Integrated queries and interoperable heterogeneous execution. In Proceedings of the ACM SIGPLAN Workshop on ML and its Applications, 2006b. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Don Syme and James Margetson. F# website. research.microsoft.com/fsharp, 2006.Google ScholarGoogle Scholar
  27. Walid Taha and Tim Sheard. Multi-stage programming with explicit annotations. In Partial Evaluation and Semantics-Based Program Manipulation. ACM, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Mark Tullsen. First class patterns. In Practical Aspects of Declarative Languages. Springer, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Philip Wadler. Views: A way for pattern matching to cohabit with data abstraction. In Principles of Programming Languages. ACM, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Hongwei Xi, Chiyan Chen, and Gang Chen. Guarded recursive datatype constructors. In Proceedings of the 30th ACM SIGPLAN-SIGACT symposium on Principles of Programming Languages, pages 224--235, New York, NY, USA, 2003. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Extensible pattern matching via a lightweight language extension

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 42, Issue 9
      Proceedings of the ICFP '07 conference
      September 2007
      331 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/1291220
      Issue’s Table of Contents
      • cover image ACM Conferences
        ICFP '07: Proceedings of the 12th ACM SIGPLAN international conference on Functional programming
        October 2007
        346 pages
        ISBN:9781595938152
        DOI:10.1145/1291151

      Copyright © 2007 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 1 October 2007

      Check for updates

      Qualifiers

      • article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!