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.
Supplemental Material
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Robin Cockett. 1996. Charitable Thoughts. http://pll.cpsc.ucalgary.ca/charity1/www/home. html (draft lecture notes).Google Scholar
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- Robert Harper. 1999. Proof-directed debugging. Journal of Functional Programming 9, 4 ( 1999 ), 463-469. https://doi.org/10. 1017/S0956796899003378 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- Christopher Jenkins and Aaron Stump. 2020. Monotone recursive types and recursive data representations in Cedille. arXiv:cs.PL/ 2001.02828Google Scholar
- 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 Scholar
- Andrew Kent. 2017. Refinement Types in Typed Racket. https://blog.racket-lang.org/ 2017 /11/adding-refinement-types.htmlGoogle Scholar
- Joomy Korkut, Maksim Trifunovski, and Daniel Licata. 2016. Intrinsic Verification of a Regular Expression Matcher. Unpublished, available from Licata's web site.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- Lambert Meertens. 1992. Paramorphisms. Form. Asp. Comput. 4, 5 (Sept. 1992 ), 413-424.Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Aaron Stump. 2017. The calculus of dependent lambda eliminations. J. Funct. Program. 27 ( 2017 ), e14. https://doi.org/10. 1017/S0956796817000053 Google Scholar
Cross Ref
- 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 Scholar
Cross Ref
- Aaron Stump. 2018b. Syntax and Semantics of Cedille. CoRR abs/ 1806.04709 ( 2018 ). arXiv: 1806.04709 http://arxiv.org/abs/ 1806.04709Google Scholar
- Aaron Stump. 2018c. Syntax and Typing for Cedille Core. CoRR abs/ 1811.01318 ( 2018 ). arXiv: 1811.01318 http://arxiv.org/ abs/ 1811.01318Google Scholar
- Wouter Swierstra. 2008. Data Types à La Carte. J. Funct. Program. 18, 4 ( July 2008 ), 423-436.Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Strong functional pearl: Harper’s regular-expression matcher in Cedille
Recommendations
Type-FUNCTIONAL PEARL safe cast
Comparing two types for equality is an essential ingredient for an implementation of dynamic types. Once equality has been established, it is safe to cast a value from one type to another. In a language with run-time type analysis, implementing such a ...
Functional pearl: implicit configurations--or, type classes reflect the values of types
Haskell '04: Proceedings of the 2004 ACM SIGPLAN workshop on HaskellThe configurations problem is to propagate run-time preferences throughout a program, allowing multiple concurrent configuration sets to coexist safely under statically guaranteed separation. This problem is common in all software systems, but ...
Functional Pearl: The Distributive -Calculus
Functional and Logic ProgrammingAbstractWe introduce a simple extension of the -calculus with pairs—called the distributive -calculus—obtained by adding a computational interpretation of the valid distributivity isomorphism of simple types. We study the calculus both as an untyped and ...






Comments