skip to main content
research-article
Open Access

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

Published:03 August 2020Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

Presentation at ICFP '20

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 Google ScholarGoogle ScholarCross RefCross Ref
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Robin Cockett. 1996. Charitable Thoughts. http://pll.cpsc.ucalgary.ca/charity1/www/home. html (draft lecture notes).Google ScholarGoogle Scholar
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  15. Robert Harper. 1999. Proof-directed debugging. Journal of Functional Programming 9, 4 ( 1999 ), 463-469. https://doi.org/10. 1017/S0956796899003378 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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= 44275Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.08233Google ScholarGoogle Scholar
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Christopher Jenkins and Aaron Stump. 2020. Monotone recursive types and recursive data representations in Cedille. arXiv:cs.PL/ 2001.02828Google ScholarGoogle Scholar
  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/41230Google ScholarGoogle Scholar
  23. Andrew Kent. 2017. Refinement Types in Typed Racket. https://blog.racket-lang.org/ 2017 /11/adding-refinement-types.htmlGoogle ScholarGoogle Scholar
  24. Joomy Korkut, Maksim Trifunovski, and Daniel Licata. 2016. Intrinsic Verification of a Regular Expression Matcher. Unpublished, available from Licata's web site.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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/956895891Google ScholarGoogle Scholar
  28. Lambert Meertens. 1992. Paramorphisms. Form. Asp. Comput. 4, 5 (Sept. 1992 ), 413-424.Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Aaron Stump. 2017. The calculus of dependent lambda eliminations. J. Funct. Program. 27 ( 2017 ), e14. https://doi.org/10. 1017/S0956796817000053 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  36. Aaron Stump. 2018b. Syntax and Semantics of Cedille. CoRR abs/ 1806.04709 ( 2018 ). arXiv: 1806.04709 http://arxiv.org/abs/ 1806.04709Google ScholarGoogle Scholar
  37. Aaron Stump. 2018c. Syntax and Typing for Cedille Core. CoRR abs/ 1811.01318 ( 2018 ). arXiv: 1811.01318 http://arxiv.org/ abs/ 1811.01318Google ScholarGoogle Scholar
  38. Wouter Swierstra. 2008. Data Types à La Carte. J. Funct. Program. 18, 4 ( July 2008 ), 423-436.Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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.Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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. 774462Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

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

        Recommendations

        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

        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!