Refactoring pattern matching

  • Authors:
  • Meng Wang;Jeremy Gibbons;Kazutaka Matsuda;Zhenjiang Hu

  • Affiliations:
  • Computer Science and Engineering, Chalmers University of Technology, 412 96 Göteborg, Sweden;Department of Computer Science, Oxford University, Wolfson Building, Parks Road, Oxford OX1 3QD, UK;Graduate School of Information Sciences, Tohoku University, Aramaki aza Aoba 6-3-09, Aoba-ku, Sendai-city, Miyagi-pref. 980-8579, Japan;GRACE Center, National Institute of Informatics, 2-1-2 Hitotsubashi, Chiyoda-ku, Tokyo101-8430, Japan

  • Venue:
  • Science of Computer Programming
  • Year:
  • 2013

Quantified Score

Hi-index 0.00

Visualization

Abstract

Defining functions by pattern matching over the arguments is advantageous for understanding and reasoning, but it tends to expose the implementation of a datatype. Significant effort has been invested in tackling this loss of modularity; however, decoupling patterns from concrete representations while maintaining soundness of reasoning has been a challenge. Inspired by the development of invertible programming, we propose an approach to program refactoring based on a right-invertible language rinv-every function has a right (or pre-) inverse. We show how this new design is able to permit a smooth incremental transition from programs with algebraic datatypes and pattern matching, to ones with proper encapsulation, while maintaining simple and sound reasoning.