Advertisement

Non-linear Pattern Matching with Backtracking for Non-free Data Types

  • Satoshi Egi
  • Yuichi Nishiwaki
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11275)

Abstract

Non-free data types are data types whose data have no canonical forms. For example, multisets are non-free data types because the multiset \(\{a,b,b\}\) has two other equivalent but literally different forms \(\{b,a,b\}\) and \(\{b,b,a\}\). Pattern matching is known to provide a handy tool set to treat such data types. Although many studies on pattern matching and implementations for practical programming languages have been proposed so far, we observe that none of these studies satisfy all the criteria of practical pattern matching, which are as follows: (i) efficiency of the backtracking algorithm for non-linear patterns, (ii) extensibility of matching process, and (iii) polymorphism in patterns.

This paper aims to design a new pattern-matching-oriented programming language that satisfies all the above three criteria. The proposed language features clean Scheme-like syntax and efficient and extensible pattern matching semantics. This programming language is especially useful for the processing of complex non-free data types that not only include multisets and sets but also graphs and symbolic mathematical expressions. We discuss the importance of our criteria of practical pattern matching and how our language design naturally arises from the criteria. The proposed language has been already implemented and open-sourced as the Egison programming language.

Notes

Acknowledgments

We thank Ryo Tanaka, Takahisa Watanabe, Kentaro Honda, Takuya Kuwahara, Mayuko Kori, and Akira Kawata for their important contributions to implement the interpreter. We thank Michal J. Gajda, Yi Dai, Hiromi Hirano, Kimio Kuramitsu, and Pierre Imai for their helpful feedback on the earlier versions of the paper. We thank Masami Hagiya, Yoshihiko Kakutani, Yoichi Hirai, Ibuki Kawamata, Takahiro Kubota, Takasuke Nakamura, Yasunori Harada, Ikuo Takeuchi, Yukihiro Matsumoto, Hidehiko Masuhara, and Yasuhiro Yamada for constructive discussion and their continuing encouragement.

References

  1. 1.
    Attributes::attnf - Wolfram Language Documentation. http://reference.wolfram.com/language/ref/message/Attributes/attnf.html. Accessed 14 June 2018
  2. 2.
    Introduction to Patterns - Wolfram Language Documentation. http://reference.wolfram.com/language/tutorial/Introduction-Patterns.html. Accessed 14 June 2018
  3. 3.
    Orderless - Wolfram Language Documentation. http://reference.wolfram.com/language/ref/Orderless.html. Accessed 14 June 2018
  4. 4.
    PAKCS. https://www.informatik.uni-kiel.de/~pakcs/. Accessed 14 June 2018
  5. 5.
    ViewPatterns - GHC. https://ghc.haskell.org/trac/ghc/wiki/ViewPatterns. Accessed 14 June 2018
  6. 6.
    The Egison programming language (2011). https://www.egison.org. Accessed 14 June 2018
  7. 7.
    Egison Mathematics Notebook (2016). https://www.egison.org/math. Accessed 14 June 2018
  8. 8.
    Antoy, S.: Programming with narrowing: a tutorial. J. Symb. Comput. 45(5), 501–522 (2010)MathSciNetCrossRefGoogle Scholar
  9. 9.
    Antoy, S.: Constructor-based conditional narrowing. In: Proceedings of the 3rd ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming (2001)Google Scholar
  10. 10.
    Antoy, S., Hanus, M.: Functional logic programming. Commun. ACM 53(4), 74–85 (2010)CrossRefGoogle Scholar
  11. 11.
    Braßel, B., Hanus, M., Peemöller, B., Reck, F.: KiCS2: a new compiler from Curry to Haskell. In: Kuchen, H. (ed.) WFLP 2011. LNCS, vol. 6816, pp. 1–18. Springer, Heidelberg (2011).  https://doi.org/10.1007/978-3-642-22531-4_1CrossRefGoogle Scholar
  12. 12.
    Egi, S.: Non-linear pattern matching against non-free data types with lexical scoping. arXiv preprint arXiv:1407.0729 (2014)
  13. 13.
    Egi, S.: Scalar and tensor parameters for importing tensor index notation including Einstein summation notation. In: The Scheme and Functional Programming Workshop (2017)Google Scholar
  14. 14.
    Egi, S.: Scalar and tensor parameters for importing the notation in differential geometry into programming. arXiv preprint arXiv:1804.03140 (2018)
  15. 15.
    Erwig, M.: Active patterns. In: Kluge, W. (ed.) IFL 1996. LNCS, vol. 1268, pp. 21–40. Springer, Heidelberg (1997).  https://doi.org/10.1007/3-540-63237-9_17CrossRefGoogle Scholar
  16. 16.
    Erwig, M.: Functional programming with graphs. In: ACM SIGPLAN Notices, vol. 32 (1997)CrossRefGoogle Scholar
  17. 17.
    Fischer, S., Kiselyov, O., Shan, C.: Purely functional lazy non-deterministic programming. In: ACM Sigplan Notices, vol. 44 (2009)CrossRefGoogle Scholar
  18. 18.
    Hanus, M.: Multi-paradigm declarative languages. In: Dahl, V., Niemelä, I. (eds.) ICLP 2007. LNCS, vol. 4670, pp. 45–75. Springer, Heidelberg (2007).  https://doi.org/10.1007/978-3-540-74610-2_5CrossRefGoogle Scholar
  19. 19.
    Hinze, R., Paterson, R.: Finger trees: a simple general-purpose data structure. J. Funct. Program. 16(2), 197–217 (2006)MathSciNetCrossRefGoogle Scholar
  20. 20.
    Krebber, M.: Non-linear associative-commutative many-to-one pattern matching with sequence variables. arXiv preprint arXiv:1705.00907 (2017)
  21. 21.
    McBride, F., Morrison, D., Pengelly, R.: A symbol manipulation system. Mach. Intell. 5, 337–347 (1969)Google Scholar
  22. 22.
    Okasaki, C.: Views for standard ML. In: SIGPLAN Workshop on ML (1998)Google Scholar
  23. 23.
    Syme, D., Neverov, G., Margetson, J.: Extensible pattern matching via a lightweight language extension. In: ACM SIGPLAN Notices, vol. 42 (2007)CrossRefGoogle Scholar
  24. 24.
    Thompson, S.: Lawful functions and program verification in Miranda. Sci. Comput. Program. 13(2–3), 181–218 (1990)MathSciNetCrossRefGoogle Scholar
  25. 25.
    Thompson, S.: Laws in Miranda. In: Proceedings of the 1986 ACM Conference on LISP and Functional Programming (1986)Google Scholar
  26. 26.
    Tullsen, M.: First class patterns? In: Pontelli, E., Santos Costa, V. (eds.) PADL 2000. LNCS, vol. 1753, pp. 1–15. Springer, Heidelberg (1999).  https://doi.org/10.1007/3-540-46584-7_1CrossRefGoogle Scholar
  27. 27.
    Turner, D.A.: Miranda: a non-strict functional language with polymorphic types. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 1–16. Springer, Heidelberg (1985).  https://doi.org/10.1007/3-540-15975-4_26CrossRefGoogle Scholar
  28. 28.
    Wadler, P.: Views: a way for pattern matching to cohabit with data abstraction. In: Proceedings of the 14th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (1987)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2018

Authors and Affiliations

  1. 1.Rakuten Institute of TechnologyTokyoJapan
  2. 2.University of TokyoTokyoJapan

Personalised recommendations