Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Strong functional pearl: Harper’s regular-expression matcher in Cedille

Published: 03 August 2020 Publication History

Abstract

This paper describes an implementation of Harper's continuation-based regular-expression matcher as a strong functional program in Cedille; i.e., Cedille statically confirms termination of the program on all inputs. The approach uses neither dependent types nor termination proofs. Instead, a particular interface dubbed a recursion universe is provided by Cedille, and the language ensures that all programs written against this interface terminate. Standard polymorphic typing is all that is needed to check the code against the interface. This answers a challenge posed by Bove, Krauss, and Sozeau.

Supplementary Material

Presentation at ICFP '20 (a122-stump-presentation.mp4)

References

[1]
Jirí Adámek, Dominik Lücke, and Stefan Milius. 2007. Recursive coalgebras of finitary functors. Informatique Théorique et Applications 41, 4 ( 2007 ), 447-462. https://doi.org/10.1051/ita:2007028
[2]
Ki Yung Ahn and Tim Sheard. 2011. A hierarchy of mendler style recursion combinators: taming inductive datatypes with negative occurrences. In Proceeding of the 16th ACM SIGPLAN international conference on Functional Programming, ICFP 2011, Tokyo, Japan, September 19-21, 2011, Manuel M. T. Chakravarty, Zhenjiang Hu, and Olivier Danvy (Eds.). ACM, 234-246.
[3]
Bruno Barras and Bruno Bernardo. 2008. The Implicit Calculus of Constructions as a Programming Language with Dependent Types. In Foundations of Software Science and Computational Structures, 11th International Conference, FOSSACS 2008, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2008, Budapest, Hungary, March 29-April 6, 2008. Proceedings (Lecture Notes in Computer Science), Roberto M. Amadio (Ed.), Vol. 4962. Springer, 365-379. https://doi.org/10.1007/978-3-540-78499-9_26
[4]
Gilles Barthe, Maria João Frade, Eduardo Giménez, Luís Pinto, and Tarmo Uustalu. 2004. Type-based termination of recursive definitions. Mathematical Structures in Computer Science 14, 1 ( 2004 ), 97-141. https://doi.org/10.1017/S0960129503004122
[5]
Ana Bove, Alexander Krauss, and Matthieu Sozeau. 2016. Partiality and recursion in interactive theorem provers-an overview. Mathematical Structures in Computer Science 26, 1 ( 2016 ), 38-88. https://doi.org/10.1017/S0960129514000115
[6]
J. Robin B. Cockett and Dwight Spencer. 1995. Strong Categorical Datatypes II: A Term Logic for Categorical Programming. Theor. Comput. Sci. 139, 1 & 2 ( 1995 ), 69-113. https://doi.org/10.1016/ 0304-3975 ( 94 ) 00099-5
[7]
Robin Cockett. 1996. Charitable Thoughts. http://pll.cpsc.ucalgary.ca/charity1/www/home. html (draft lecture notes).
[8]
Robert L. Constable and Scott F. Smith. 1987. Partial Objects In Constructive Type Theory. In Proceedings of the Symposium on Logic in Computer Science (LICS '87), Ithaca, New York, USA, June 22-25, 1987. IEEE Computer Society, 183-193.
[9]
Ernesto Copello, Alvaro Tasistro, and Bruno Bianchi. 2014. Case of (Quite) Painless Dependently Typed Programming: Fully Certified Merge Sort in Agda. In Programming Languages-18th Brazilian Symposium, SBLP 2014, Maceio, Brazil, October 2-3, 2014. Proceedings (Lecture Notes in Computer Science), Fernando Magno Quintão Pereira (Ed.), Vol. 8771. Springer, 62-76. https://doi.org/10.1007/978-3-319-11863-5_5
[10]
Nils Anders Danielsson. 2010. Total Parser Combinators. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming (ICFP '10). Association for Computing Machinery, New York, NY, USA, 285-296. https: //doi.org/10.1145/1863543.1863585
[11]
Olivier Danvy and Lasse Nielsen. 2001. Defunctionalization at Work. BRICS Report Series 8, 23 (Jun. 2001 ). https: //doi.org/10.7146/brics.v8i23. 21684
[12]
Denis Firsov, Richard Blair, and Aaron Stump. 2018. Eficient Mendler-Style Lambda-Encodings in Cedille. In Interactive Theorem Proving, Jeremy Avigad and Assia Mahboubi (Eds.). Springer International Publishing, Cham, 235-252.
[13]
Jürgen Giesl, Cornelius Aschermann, Marc Brockschmidt, Fabian Emmes, Florian Frohn, Carsten Fuhs, Jera Hensel, Carsten Otto, Martin Plücker, Peter Schneider-Kamp, Thomas Ströder, Stephanie Swiderski, and René Thiemann. 2017. Analyzing Program Termination and Complexity Automatically with AProVE. Journal of Automated Reasoning 58, 1 ( 2017 ), 3-31. https://doi.org/10.1007/s10817-016-9388-y
[14]
Jürgen Giesl, Albert Rubio, Christian Sternagel, Johannes Waldmann, and Akihisa Yamada. 2019. The Termination and Complexity Competition. In Tools and Algorithms for the Construction and Analysis of Systems, Dirk Beyer, Marieke Huisman, Fabrice Kordon, and Bernhard Stefen (Eds.). Springer International Publishing, Cham, 156-166.
[15]
Robert Harper. 1999. Proof-directed debugging. Journal of Functional Programming 9, 4 ( 1999 ), 463-469. https://doi.org/10. 1017/S0956796899003378
[16]
Ralf Hinze. 2013. Adjoint folds and unfolds-An extended study. Science of Computer Programming 78, 11 ( 2013 ), 2108-2159. https://doi.org/10.1016/j.scico. 2012. 07.011
[17]
Markus Holzer and Martin Kutrib. 2010. The Complexity of Regular(-Like) Expressions. In Developments in Language Theory, Yuan Gao, Hanlin Lu, Shinnosuke Seki, and Sheng Yu (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 16-30.
[18]
Graham Hutton. 1999. A Tutorial on the Universality and Expressiveness of Fold. J. Funct. Program. 9, 4 ( 1999 ), 355-372. http://journals.cambridge.org/action/displayAbstract?aid= 44275
[19]
Christopher Jenkins, Colin McDonald, and Aaron Stump. 2019. Elaborating Inductive Datatypes and Course-of-Values Pattern Matching to Cedille. CoRR abs/ 1903.08233 ( 2019 ). arXiv: 1903.08233 http://arxiv.org/abs/ 1903.08233
[20]
Christopher Jenkins and Aaron Stump. 2018. Spine-local Type Inference. In Proceedings of the 30th Symposium on Implementation and Application of Functional Languages, IFL 2018, Lowell, MA, USA, September 5-7, 2018, Matteo Cimini and Jay McCarthy (Eds.). ACM, 37-48.
[21]
Christopher Jenkins and Aaron Stump. 2020. Monotone recursive types and recursive data representations in Cedille. arXiv:cs.PL/ 2001.02828
[22]
Ryo Kashima. 2001. A Proof of the Standardization Theorem in λ-Calculus. Lecture Notes: RIMS Kokyuroku Bessatsu 1217 ( June 2001 ). http://hdl.handle. net/2433/41230
[23]
Andrew Kent. 2017. Refinement Types in Typed Racket. https://blog.racket-lang.org/ 2017 /11/adding-refinement-types.html
[24]
Joomy Korkut, Maksim Trifunovski, and Daniel Licata. 2016. Intrinsic Verification of a Regular Expression Matcher. Unpublished, available from Licata's web site.
[25]
Alexander Krauss. 2010. Partial and Nested Recursive Function Definitions in Higher-order Logic. J. Autom. Reasoning 44, 4 ( 2010 ), 303-336. https://doi.org/10.1007/s10817-009-9157-2
[26]
Sam Lindley and Conor McBride. 2013. Hasochism: The Pleasure and Pain of Dependently Typed Haskell Programming. SIGPLAN Not. 48, 12 (Sept. 2013 ), 81-92. https://doi.org/10.1145/2578854.2503786
[27]
Ralph Matthes. 1999. Extensions of system F by iteration and primitive recursion on monotone inductive types. Ph.D. Dissertation. Ludwig Maximilian University of Munich, Germany. http://d-nb. info/956895891
[28]
Lambert Meertens. 1992. Paramorphisms. Form. Asp. Comput. 4, 5 (Sept. 1992 ), 413-424.
[29]
Erik Meijer, Maarten M. Fokkinga, and Ross Paterson. 1991. Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire. In Functional Programming Languages and Computer Architecture, 5th ACM Conference, Cambridge, MA, USA, August 26-30, 1991, Proceedings (Lecture Notes in Computer Science), John Hughes (Ed.), Vol. 523. Springer, 124-144. https://doi.org/10.1007/3540543961_7
[30]
Nax Paul Mendler. 1991. Inductive types and type constraints in the second-order lambda calculus. Annals of Pure and Applied Logic 51, 1 ( 1991 ), 159-172. https://doi.org/10.1016/ 0168-0072 ( 91 ) 90069-X
[31]
Scott Owens and Konrad Slind. 2008. Adapting functional programs to higher order logic. Higher-Order and Symbolic Computation 21, 4 ( 2008 ), 377-409. https://doi.org/10.1007/s10990-008-9038-0
[32]
Michel Parigot. 1989. On the Representation of Data in Lambda-Calculus. In CSL ' 89, 3rd Workshop on Computer Science Logic, Kaiserslautern, Germany, October 2-6, 1989, Proceedings (Lecture Notes in Computer Science), Egon Börger, Hans Kleine Büning, and Michael M. Richter (Eds.), Vol. 440. Springer, 309-321. https://doi.org/10.1007/3-540-52753-2_47
[33]
Morten Heine Sørensen and Pawel Urzyczyn. 2006. Lectures on the Curry-Howard Isomorphism, Volume 149 ( Studies in Logic and the Foundations of Mathematics). Elsevier Science Inc.
[34]
Aaron Stump. 2017. The calculus of dependent lambda eliminations. J. Funct. Program. 27 ( 2017 ), e14. https://doi.org/10. 1017/S0956796817000053
[35]
Aaron Stump. 2018a. From realizability to induction via dependent intersection. Ann. Pure Appl. Log. 169, 7 ( 2018 ), 637-655. https://doi.org/10.1016/j.apal. 2018. 03.002
[36]
Aaron Stump. 2018b. Syntax and Semantics of Cedille. CoRR abs/ 1806.04709 ( 2018 ). arXiv: 1806.04709 http://arxiv.org/abs/ 1806.04709
[37]
Aaron Stump. 2018c. Syntax and Typing for Cedille Core. CoRR abs/ 1811.01318 ( 2018 ). arXiv: 1811.01318 http://arxiv.org/ abs/ 1811.01318
[38]
Wouter Swierstra. 2008. Data Types à La Carte. J. Funct. Program. 18, 4 ( July 2008 ), 423-436.
[39]
Alastair Telford and David Turner. 2000. Ensuring Termination in ESFP. 6, 4 (apr 2000 ), 474-488. http://www.jucs.org/jucs_6_4/ensuring_termination_in_esfp.
[40]
D. A. Turner. 1995. Elementary Strong Functional Programming. In Proceedings of the First International Symposium on Functional Programming Languages in Education (FPLE '95). Springer-Verlag, Berlin, Heidelberg, 1-13.
[41]
D. A. Turner. 2004. Total Functional Programming. Journal of Universal Computer Science 10, 7 ( 2004 ), 751-768. https: //doi.org/10.3217/jucs-010-07-0751
[42]
Tarmo Uustalu and Varmo Vene. 1999. Mendler-style Inductive Types, Categorically. Nordic J. of Computing 6, 3 (sep 1999 ), 343-361. http://dl.acm.org/citation.cfm?id= 774455. 774462
[43]
Tarmo Uustalu and Varmo Vene. 2000. Coding Recursion a la Mendler (Extended Abstract). In Proc. of the 2nd Workshop on Generic Programming, WGP 2000, Technical Report UU-CS-2000-19. Dept. of Computer Science, Utrecht University, 69-85.
[44]
Niki Vazou, Eric L. Seidel, and Ranjit Jhala. 2014. LiquidHaskell: Experience with Refinement Types in the Real World. SIGPLAN Not. 49, 12 (Sept. 2014 ), 39-51. https://doi.org/10.1145/2775050.2633366
[45]
Stephanie Weirich, Pritam Choudhury, Antoine Voizard, and Richard A. Eisenberg. 2019. A role for dependent types in Haskell. PACMPL 3, ICFP ( 2019 ), 101 : 1-101 : 29. https://doi.org/10.1145/3341705
[46]
Stephanie Weirich, Antoine Voizard, Pedro Henrique Avezedo de Amorim, and Richard A. Eisenberg. 2017. A specification for dependent types in Haskell. PACMPL 1, ICFP ( 2017 ), 31 : 1-31 : 29. https://doi.org/10.1145/3110275
[47]
Hongwei Xi. 2002. Dependent Types for Program Termination Verification. Higher-Order and Symbolic Computation 15, 1 (March 2002 ), 91-131. https://doi.org/10.1023/A:1019916231463

Cited By

View all
  • (2023)A Type-Based Approach to Divide-and-Conquer Recursion in CoqProceedings of the ACM on Programming Languages10.1145/35711967:POPL(61-90)Online publication date: 11-Jan-2023

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 4, Issue ICFP
August 2020
1070 pages
EISSN:2475-1421
DOI:10.1145/3415018
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 03 August 2020
Published in PACMPL Volume 4, Issue ICFP

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. programming with continuations
  2. recursion schemes
  3. regular-expression matcher
  4. strong functional programming

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)149
  • Downloads (Last 6 weeks)27
Reflects downloads up to 03 Oct 2024

Other Metrics

Citations

Cited By

View all
  • (2023)A Type-Based Approach to Divide-and-Conquer Recursion in CoqProceedings of the ACM on Programming Languages10.1145/35711967:POPL(61-90)Online publication date: 11-Jan-2023

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media