Skip to main content Accessibility help
×
Home
Hostname: page-component-5959bf8d4d-4p99k Total loading time: 0.245 Render date: 2022-12-07T21:55:12.182Z Has data issue: true Feature Flags: { "useRatesEcommerce": false } hasContentIssue true

Elaborating dependent (co)pattern matching: No pattern left behind

Part of: ICFP2018

Published online by Cambridge University Press:  21 January 2020

JESPER COCKX
Affiliation:
Chalmers and Gothenburg University, Sweden (until October 2019) and TU Delft, Netherlands (from December 2019) (e-mail: jesper@sikanda.be)
ANDREAS ABEL
Affiliation:
Chalmers and Gothenburg University, Sweden (e-mail: andreas.abel@gu.se)
Rights & Permissions[Opens in a new window]

Abstract

HTML view is not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

In a dependently typed language, we can guarantee correctness of our programmes by providing formal proofs. To check them, the typechecker elaborates these programs and proofs into a low-level core language. However, this core language is by nature hard to understand by mere humans, so how can we know we proved the right thing? This question occurs in particular for dependent copattern matching, a powerful language construct for writing programmes and proofs by dependent case analysis and mixed induction/coinduction. A definition by copattern matching consists of a list of clauses that are elaborated to a case tree, which can be further translated to primitive eliminators. In previous work this second step has received a lot of attention, but the first step has been mostly ignored so far. We present an algorithm elaborating definitions by dependent copattern matching to a core language with inductive data types, coinductive record types, an identity type, and constants defined by well-typed case trees. To ensure correctness, we prove that elaboration preserves the first-match semantics of the user clauses. Based on this theoretical work, we reimplement the algorithm used by Agda to check left-hand sides of definitions by pattern matching. The new implementation is at the same time more general and less complex, and fixes a number of bugs and usability issues with the old version. Thus, we take another step towards the formally verified implementation of a practical dependently typed language.

Type
Research Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution, and reproduction in any medium, provided the original work is properly cited.
Copyright
© Cambridge University Press 2020

References

Abel, A. & Pientka, B. (2013) Wellfounded recursion with copatterns: A unified approach to termination and productivity. In Proceedings of the Eighteenth ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA, September 25–27, 2013, Morrisett, G. & Uustalu, T. (eds). ACM Press, pp. 185196. Available at: http://doi.acm.org/10.1145/2500365.2500591CrossRefGoogle Scholar
Abel, A., Pientka, B., Thibodeau, D. & Setzer, A. (2013) Copatterns: Programming infinite structures by observations. In The 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL’13, Rome, Italy, January 23–25, 2013, Giacobazzi, R. & Cousot, R. (eds). ACM Press, pp. 2738. Available at: http://dl.acm.org/citation.cfm?id=2429069CrossRefGoogle Scholar
Agda development team. (2017) Agda 2.5.3 documentation. Available at: http://agda.readthedocs.io/en/v2.5.3/Google Scholar
Agda issue. (2017a) Disambiguation of type based on pattern leads to non-unique meta solution. Available at: https://github.com/agda/agda/issues/2834 (on the Agda bug tracker).Google Scholar
Agda issue. (2017b) Record constructor is accepted, record pattern is not. Available at: https://github.com/agda/agda/issues/2850 (on the Agda bug tracker).Google Scholar
Agda issue (2017c). Panic: Unbound variable. Available at: https://github.com/agda/agda/issues/2856 (on the Agda bug tracker).Google Scholar
Agda issue. (2017d) Internal error in src/full/agda/typechecking/coverage/match.hs:312. Available at: https://github.com/agda/agda/issues/2874. (on the Agda bug tracker).Google Scholar
Agda issue. (2018a) Unifier throws away pattern. Available at: https://github.com/agda/agda/issues/2896. (on the Agda bug tracker).Google Scholar
Agda issue. (2018b) Mismatch between order of matching in clauses and case tree; subject reduction broken. Available at: https://github.com/agda/agda/issues/2964. (on the Agda bug tracker).Google Scholar
Andreoli, J.-M. (1992) Logic programming with focusing proofs in linear logic. J. Logic Comput. 2(3), 297347. Available at: https://doi.org/10.1093/logcom/2.3.297.CrossRefGoogle Scholar
Augustsson, L. (1985) Compiling pattern matching. In Functional Programming Languages and Computer Architecture, FPCA 1985, Nancy, France, Proceedings September 16–19, 1985, vol. 201. Lecture Notes in Computer Science. Springer, pp. 368381. Available at: https://doi.org/10.1007/3-540-15975-4_48.CrossRefGoogle Scholar
Blanchette, J. C., Bouzy, A., Lochbihler, A., Popescu, A. & Traytel, D. (2017) Friends with benefits – implementing corecursion in foundational proof assistants. In Programming Languages and Systems – 26th European Symposium on Programming, ESOP 2017, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2017, Uppsala, Sweden, April 22–29, 2017, Proceedings, Yang, H. (ed), vol. 10201. Lecture Notes in Computer Science. Springer, pp. 111140. Available at: https://doi.org/10.1007/978-3-662-54434-1_5CrossRefGoogle Scholar
Brady, E. (2013) Idris, a general-purpose dependently typed programming language: Design and implementation. J. Functional Program. 23(5), 552593. Available at: http://dx.doi.org/10.1017/S095679681300018XCrossRefGoogle Scholar
Brady, E., McBride, C. & McKinna, J. (2003) Inductive families need not store their indices. In Types for Proofs and Programs, International Workshop, TYPES 2003, Torino, Italy, April 30–May 4, 2003, Revised Selected Papers, Berardi, S., Coppo, M. & Damiani, F. (eds), vol. 3085. Lecture Notes in Computer Science. Springer, pp. 115129. Available at: https://doi.org/10.1007/978-3-540-24849-1_8CrossRefGoogle Scholar
Cardelli, L. (1984) Compiling a functional language. In Proceedings of the 1984 ACM Conference on LISP and Functional Programming, August 5–8, 1984, Austin, Texas, USA. ACM Press, pp. 208217. Available at: http://lucacardelli.name/Papers/CompilingML.A4.pdfCrossRefGoogle Scholar
Cockx, J. (2017) Dependent pattern matching and proof-relevant unification. PhD thesis, KU Leuven, 2017.Google Scholar
Cockx, J. & Abel, A. (2018) Elaborating dependent (co)pattern matching. PACMPL, 2(ICFP), 75:175:30. Available at: https://doi.org/10.1145/3236770.Google Scholar
Cockx, J., Devriese, D. & Piessens, F. (2016) Unifiers as equivalences: Proof-relevant unification of dependently typed data. In Garrigue et al.(2016), pp. 270283. Available at: http://doi.acm.org/10.1145/2951913.2951917.Google Scholar
Coquand, T. (1992) Pattern matching with dependent types. In Proceedings of the 1992 Workshop on Types for Proofs and Programs, Båstad, Sweden, June 1992, Nordström, B., Pettersson, K. & Plotkin, G. (eds). Chalmers University of Technology, pp. 7183, 1992. Available at: http://www.cse.chalmers.se/~coquand/pattern.psGoogle Scholar
de Bruijn, N. G. (1991) Telescopic mappings in typed lambda calculus. Inf. Comput. 91(2), 189204. Available at: https://doi.org/10.1016/0890-5401(91)90066-BCrossRefGoogle Scholar
de Moura, L. M., Kong, S., Avigad, J., van Doorn, F. & von Raumer, J. (2015) The Lean theorem prover (system description). In Automated Deduction – CADE-25 – 25th International Conference on Automated Deduction, Berlin, Germany, August 1–7, 2015, Proceedings, Felty, A. P. & Middeldorp, A. (eds), vol. 9195. Lecture Notes in Computer Science. Springer, pp. 378388 Available at: https://doi.org/10.1007/978-3-319-21401-6_26CrossRefGoogle Scholar
Garrigue, J., Keller, G. & Sumii, E. (eds). Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming, ICFP 2016, Nara, Japan, September 18–22, 2016. ACM Press. Available at: http://doi.acm.org/10.1145/2951913Google Scholar
Goguen, H., McBride, C. & McKinna, J. (2006) Eliminating dependent pattern matching. In Algebra, Meaning, and Computation, Essays Dedicated to Joseph A. Goguen on the Occasion of His 65th Birthday, Futatsugi, K., Jouannaud, J.-P. & Meseguer, J. (eds), vol. 4060. Lecture Notes in Computer Science. Springer, pp. 521540. Available at: https://doi.org/10.1007/11780274_27CrossRefGoogle Scholar
INRIA. (2017) The Coq Proof Assistant Reference Manual. INRIA, version 8.7 edition, Available at: http://coq.inria.fr/Google Scholar
Krishnaswami, N. R. (2009) Focusing on pattern matching. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009, Savannah, GA, USA, January 21–23, 2009, Shao, Z. & Pierce, B. C. (eds). ACM Press, pp. 366378. Available at: http://doi.acm.org/10.1145/1480881.1480927CrossRefGoogle Scholar
Laforgue, P. & Régis-Gianas, Y. (2017) Copattern matching and first-class observations in ocaml, with a macro. In Proceedings of the 19th International Symposium on Principles and Practice of Declarative Programming, Namur, Belgium, October 09–11, 2017, Vanhoof, W. & Pientka, B. (eds). ACM, pp. 97108. ISBN 978-1-4503-5291-8. Available at: https://doi.org/10.1145/3131851.3131869CrossRefGoogle Scholar
Licata, D. R., Zeilberger, N. & Harper, R. (2008) Focusing on binding and computation. In Proceedings of the Twenty-Third Annual IEEE Symposium on Logic in Computer Science, LICS 2008, 24–27 June 2008, Pittsburgh, PA, USA, Pfenning, F. (ed). IEEE Computer Society Press, pp. 241252. Available at: https://doi.org/10.1109/LICS.2008.48Google Scholar
Maranget, L. (1992) Compiling lazy pattern matching. In LISP and Functional Programming, pp. 2131. Available at: http://doi.acm.org/10.1145/141471.141499CrossRefGoogle Scholar
McBride, C. (2000) Dependently typed functional programs and their proofs. PhD thesis, University of Edinburgh.Google Scholar
McBride, C. & McKinna, J. (2004) The view from the left. J. Funct. Program. 14(1), 69111. Available at: https://doi.org/10.1017/S0956796803004829.CrossRefGoogle Scholar
Norell, U. (2007) Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology.Google Scholar
Oury, N. (2007) Pattern matching coverage checking with dependent types using set approximations. In Proceedings of the ACM Workshop Programming Languages meets Program Verification, PLPV 2007, Freiburg, Germany, October 5, 2007, Stump, A. & Xi, H. (eds), pp. 4756. ACM Press. Available at: http://doi.acm.org/10.1145/1292597.1292606CrossRefGoogle Scholar
Pollack, R. (1998) How to believe a machine-checked proof. In Twenty Five Years of Constructive Type Theory. Oxford University Press. Available at: http://www.brics.dk/RS/97/18/BRICS-RS-97-18.pdfCrossRefGoogle Scholar
Setzer, A., Abel, A., Pientka, B. & Thibodeau, D. (2014) Unnesting of copatterns. In Rewriting and Typed Lambda Calculi – Joint International Conference, RTA-TLCA 2014, Held as Part of the Vienna Summer of Logic, VSL 2014, Vienna, Austria, July 14-17, 2014. Proceedings, Dowek, G. (ed), vol. 8560. Lecture Notes in Computer Science. Springer, pp. 3145. Available at: http://dx.doi.org/10.1007/978-3-319-08918-8_3CrossRefGoogle Scholar
Sozeau, M. (2010) Equations: A dependent pattern-matching compiler. In Interactive Theorem Proving, First International Conference, ITP 2010, Edinburgh, UK, July 11–14, 2010. Proceedings, Kaufmann, M. & Paulson, L. C. (eds), vol. 6172. Lecture Notes in Computer Science. Springer, pp. 419434. Available at: https://doi.org/10.1007/978-3-642-14052-5_29Google Scholar
Thibodeau, D., Cave, A. & Pientka, B. (2016) Indexed codata types. In Garrigue et al. (2016), pp. 351363. Available at: http://doi.acm.org/10.1145/2951913.2951929Google Scholar
Zeilberger, N. (2008) Focusing and higher-order abstract syntax. In Proceedings of the 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2008, San Francisco, California, USA, January 7–12, 2008, Necula, G. C. & Wadler, P. (eds) pp. 359369. ACM Press. Available at: http://doi.acm.org/10.1145/1328438.1328482CrossRefGoogle Scholar
Zeilberger, N. (2009) The Logical Basis of Evaluation Order and Pattern-Matching. PhD thesis, Carnegie Mellon University. Available at: http://software.imdea.org/~noam.zeilberger/thesis.pdfGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.
You have Access Open access
1
Cited by

Save article to Kindle

To save this article to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Elaborating dependent (co)pattern matching: No pattern left behind
Available formats
×

Save article to Dropbox

To save this article to your Dropbox account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you used this feature, you will be asked to authorise Cambridge Core to connect with your Dropbox account. Find out more about saving content to Dropbox.

Elaborating dependent (co)pattern matching: No pattern left behind
Available formats
×

Save article to Google Drive

To save this article to your Google Drive account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you used this feature, you will be asked to authorise Cambridge Core to connect with your Google Drive account. Find out more about saving content to Google Drive.

Elaborating dependent (co)pattern matching: No pattern left behind
Available formats
×
×

Reply to: Submit a response

Please enter your response.

Your details

Please enter a valid email address.

Conflicting interests

Do you have any conflicting interests? *