Skip to main content
Erschienen in: New Generation Computing 2/2022

21.07.2022

Embedding Non-linear Pattern Matching with Backtracking for Non-free Data Types into Haskell

verfasst von: Satoshi Egi, Akira Kawata, Mayuko Kori, Hiromi Ogawa

Erschienen in: New Generation Computing | Ausgabe 2/2022

Einloggen

Aktivieren Sie unsere intelligente Suche, um passende Fachinhalte oder Patente zu finden.

search-config
loading …

Abstract

Pattern matching is an important language construct for data abstraction. Many pattern-match extensions have been developed for extending the range of data types to which pattern matching is applicable. Among them, the pattern-match system proposed by Egi and Nishiwaki features practical pattern matching for non-free data types by providing a user-customizable non-linear pattern-match facility with backtracking. However, they implemented their proposal only in dynamically typed programming languages, and there were no proposals that allow programmers to benefit from both static type systems and expressive pattern matching. This paper proposes a method for implementing this pattern-match facility by meta-programming in Haskell. There are two technical challenges: (i) we need to design a set of typing rules for the pattern-match facility; (ii) we need to embed these typing rules in Haskell to make types of the pattern-match expressions inferable by the Haskell type system. We propose a set of typing rules and show that several GHC extensions, such as multi-parameter type classes, datatype promotion, GADTs, existential types, and view patterns, play essential roles for embedding these typing rules into Haskell. The implementation has already been distributed as a Haskell library miniEgison via Hackage.

Sie haben noch keine Lizenz? Dann Informieren Sie sich jetzt über unsere Produkte:

Springer Professional "Wirtschaft+Technik"

Online-Abonnement

Mit Springer Professional "Wirtschaft+Technik" erhalten Sie Zugriff auf:

  • über 102.000 Bücher
  • über 537 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Maschinenbau + Werkstoffe
  • Versicherung + Risiko

Jetzt Wissensvorsprung sichern!

Springer Professional "Wirtschaft"

Online-Abonnement

Mit Springer Professional "Wirtschaft" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 340 Zeitschriften

aus folgenden Fachgebieten:

  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Versicherung + Risiko




Jetzt Wissensvorsprung sichern!

Springer Professional "Technik"

Online-Abonnement

Mit Springer Professional "Technik" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 390 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Maschinenbau + Werkstoffe




 

Jetzt Wissensvorsprung sichern!

Fußnoten
1
We borrow this notation from [8].
 
2
The definitions of the nil and join patterns are omitted.
 
Literatur
2.
Zurück zum Zitat Egi, S.: Scheme Macros for Non-linear Pattern Matching with Backtracking for Non-free Data Types. In: The Scheme and Functional Programming Workshop (2019) Egi, S.: Scheme Macros for Non-linear Pattern Matching with Backtracking for Non-free Data Types. In: The Scheme and Functional Programming Workshop (2019)
3.
Zurück zum Zitat Egi, S., Nishiwaki, Y.: Non-linear pattern matching with backtracking for non-free data types. In: Asian Symposium on Programming Languages and Systems , Springer, New York, pp. 3–23 (2018) Egi, S., Nishiwaki, Y.: Non-linear pattern matching with backtracking for non-free data types. In: Asian Symposium on Programming Languages and Systems , Springer, New York, pp. 3–23 (2018)
4.
Zurück zum Zitat Egi, S., Nishiwaki, Y.: Functional Programming in Pattern-Match-Oriented Programming Style. In: The Art, Science, and Engineering of Programming. Vol. 4, Issue 3, Article 7 (2020) Egi, S., Nishiwaki, Y.: Functional Programming in Pattern-Match-Oriented Programming Style. In: The Art, Science, and Engineering of Programming. Vol. 4, Issue 3, Article 7 (2020)
5.
Zurück zum Zitat Erwig, M.: Active patterns. Implementation of Functional Languages (1996) Erwig, M.: Active patterns. Implementation of Functional Languages (1996)
7.
Zurück zum Zitat Hudak, P., Hughes, J., Jones, S. P., Wadler, P.: A history of haskell: Being lazy with class. In: In Proceedings of the 3rd ACM SIGPLAN Conference on History of Programming Languages (HOPL-III , ACM Press, pp. 1–55 (2007) Hudak, P., Hughes, J., Jones, S. P., Wadler, P.: A history of haskell: Being lazy with class. In: In Proceedings of the 3rd ACM SIGPLAN Conference on History of Programming Languages (HOPL-III , ACM Press, pp. 1–55 (2007)
8.
Zurück zum Zitat Jones, S. P., Washburn, G., Weirich, S.: Wobbly Types: Type Inference for Generalised Algebraic Data Types. Tech. rep., Technical Report MS-CIS-05-26, Univ. of Pennsylvania (2004) Jones, S. P., Washburn, G., Weirich, S.: Wobbly Types: Type Inference for Generalised Algebraic Data Types. Tech. rep., Technical Report MS-CIS-05-26, Univ. of Pennsylvania (2004)
10.
Zurück zum Zitat Kiselyov, O., Lämmel, R., Schupke, K.: Strongly Typed Heterogeneous Collections. In Proceedings of the 2004 ACM SIGPLAN workshop on Haskell (2004), ACM, pp. 96–107 Kiselyov, O., Lämmel, R., Schupke, K.: Strongly Typed Heterogeneous Collections. In Proceedings of the 2004 ACM SIGPLAN workshop on Haskell (2004), ACM, pp. 96–107
11.
Zurück zum Zitat Kiselyov, O., Shan, C., Friedman, D. P., Sabry, A.: Backtracking, interleaving, and terminating monad transformers: (functional pearl). In Proceedings of the 10th ACM SIGPLAN International Conference on Functional Programming, ICFP 2005, Tallinn, Estonia, September 26-28, 2005 (2005), pp. 192–203 Kiselyov, O., Shan, C., Friedman, D. P., Sabry, A.: Backtracking, interleaving, and terminating monad transformers: (functional pearl). In Proceedings of the 10th ACM SIGPLAN International Conference on Functional Programming, ICFP 2005, Tallinn, Estonia, September 26-28, 2005 (2005), pp. 192–203
15.
Zurück zum Zitat Sheard, T., Jones, S. P.: Template Meta-programming for Haskell. In Proceedings of the 2002 ACM SIGPLAN workshop on Haskell (2002), ACM, pp. 1–16 Sheard, T., Jones, S. P.: Template Meta-programming for Haskell. In Proceedings of the 2002 ACM SIGPLAN workshop on Haskell (2002), ACM, pp. 1–16
17.
Zurück zum Zitat Tullsen, M.: First class patterns. In Practical Aspects of Declarative Languages, Second International Workshop, PADL 2000, Boston, MA, USA, January 2000, Proceedings (2000), E. Pontelli and V. S. Costa, Eds., vol. 1753 of Lecture Notes in Computer Science, Springer, pp. 1–15 Tullsen, M.: First class patterns. In Practical Aspects of Declarative Languages, Second International Workshop, PADL 2000, Boston, MA, USA, January 2000, Proceedings (2000), E. Pontelli and V. S. Costa, Eds., vol. 1753 of Lecture Notes in Computer Science, Springer, pp. 1–15
18.
Zurück zum Zitat Turner, D.: Some history of functional programming languages. In International Symposium on Trends in Functional Programming (2012), Springer, pp. 1–20 Turner, D.: Some history of functional programming languages. In International Symposium on Trends in Functional Programming (2012), Springer, pp. 1–20
19.
Zurück zum Zitat 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) 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)
20.
Zurück zum Zitat Wright, A. K., and Duba, B. F.: Pattern matching for Scheme. Unpublished manuscript (1993) Wright, A. K., and Duba, B. F.: Pattern matching for Scheme. Unpublished manuscript (1993)
21.
Zurück zum Zitat Yorgey, B. A., Weirich, S., Cretin, J., Peyton Jones, S., Vytiniotis, D., Magalhães, J. P.: Giving Haskell a Promotion. In Proceedings of the 8th ACM SIGPLAN workshop on Types in language design and implementation (2012), ACM, pp. 53–66 Yorgey, B. A., Weirich, S., Cretin, J., Peyton Jones, S., Vytiniotis, D., Magalhães, J. P.: Giving Haskell a Promotion. In Proceedings of the 8th ACM SIGPLAN workshop on Types in language design and implementation (2012), ACM, pp. 53–66
Metadaten
Titel
Embedding Non-linear Pattern Matching with Backtracking for Non-free Data Types into Haskell
verfasst von
Satoshi Egi
Akira Kawata
Mayuko Kori
Hiromi Ogawa
Publikationsdatum
21.07.2022
Verlag
Ohmsha
Erschienen in
New Generation Computing / Ausgabe 2/2022
Print ISSN: 0288-3635
Elektronische ISSN: 1882-7055
DOI
https://doi.org/10.1007/s00354-022-00177-z

Weitere Artikel der Ausgabe 2/2022

New Generation Computing 2/2022 Zur Ausgabe

Premium Partner