Abstract
I present a datatype-generic treatment of recursive container types whose elements are guaranteed to be stored in increasing order, with the ordering invariant rolled out systematically. Intervals, lists and binary search trees are instances of the generic treatment. On the journey to this treatment, I report a variety of failed experiments and the transferable learning experiences they triggered. I demonstrate that a total element ordering is enough to deliver insertion and flattening algorithms, and show that (with care about the formulation of the types) the implementations remain as usual. Agda's instance arguments and pattern synonyms maximize the proof search done by the typechecker and minimize the appearance of proofs in program text, often eradicating them entirely. Generalizing to indexed recursive container types, invariants such as size and balance can be expressed in addition to ordering. By way of example, I implement insertion and deletion for 2-3 trees, ensuring both order and balance by the discipline of type checking.
- William Aitken and John Reppy. Abstract value constructors. Technical Report TR 92-1290, Cornell University, 1992.Google Scholar
- Robert Atkey, Patricia Johann, and Neil Ghani. Refining inductive types. Logical Methods in Computer Science, 8 (2), 2012.Google Scholar
- Jean-Philippe Bernardy and Guilhem Moulin. Type-theory in color. In Greg Morrisett and Tarmo Uustalu, editors, ICFP, pages 61--72. ACM, 2013. ISBN 978-1-4503-2326-0. Google Scholar
Digital Library
- Rod Burstall. Proving properties of programs by structural induction. Computer Journal, 12 (1): 41--48, 1969.Google Scholar
Cross Ref
- Pierre-Évariste Dagand and Conor McBride. Transporting functions across ornaments. In Peter Thiemann and Robby Bruce Findler, editors, ICFP, pages 103--114. ACM, 2012. ISBN 978-1-4503-1054-3. Google Scholar
Digital Library
- Dominique Devriese and Frank Piessens. On the bright side of type classes: instance arguments in Agda. In Manuel M. T. Chakravarty, Zhenjiang Hu, and Olivier Danvy, editors, ICFP, pages 143--155. ACM, 2011. ISBN 978-1-4503-0865-6. Google Scholar
Digital Library
- Gérard P. Huet. The zipper. J. Funct. Program., 7 (5): 549--554, 1997. Google Scholar
Digital Library
- Patrik Jansson and Johan Jeuring. PolyP - a polytypic programming language. In Peter Lee, Fritz Henglein, and Neil D. Jones, editors, POPL, pages 470--482. ACM Press, 1997. ISBN 0-89791-853-3. Google Scholar
Digital Library
- Stefan Kahrs. Red-black trees with types. J. Funct. Program., 11 (4): 425--432, 2001. Google Scholar
Digital Library
- Fredrik Lindblad and Marcin Benke. A Tool for Automated Theorem Proving in Agda. In Jean-Christophe Filliâtre, Christine Paulin-Mohring, and Benjamin Werner, editors, TYPES, volume 3839 of Lecture Notes in Computer Science, pages 154--169. Springer, 2004. ISBN 3-540-31428-8. Google Scholar
Digital Library
- Sam Lindley and Conor McBride. Hasochism: the pleasure and pain of dependently typed haskell programming. In Chung-chieh Shan, editor, Haskell, pages 81--92. ACM, 2013. ISBN 978-1-4503-2383-3. Google Scholar
Digital Library
- Conor McBride. A Case For Dependent Families. LFCS Theory Seminar, Edinburgh, 2000. URL http://strictlypositive.org/a-case/.Google Scholar
- Conor McBride and James McKinna. The view from the left. J. Funct. Program., 14 (1): 69--111, 2004. Google Scholar
Digital Library
- Conor McBride and Ross Paterson. Applicative programming with effects. J. Funct. Program., 18 (1): 1--13, 2008. Google Scholar
Digital Library
- Matthew Might. The missing method: Deleting from Okasaki's red-black trees. Blog post, 2010. http://matt.might.net/articles/red-black-delete/.Google Scholar
- Robin Milner. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17 (3): 348--375, 1978.Google Scholar
Cross Ref
- David Turner. Elementary strong functional programming. 1987. URL http://sblp2004.ic.uff.br/papers/turner.pdf.Google Scholar
- Philip Wadler. The concatenate vanishes. Technical report, 1987.Google Scholar
- Hongwei Xi. Dependently Typed Data Structures. In Proceedings of Workshop of Algorithmic Aspects of Advanced Programming Languages (WAAAPL '99), pages 17--32, Paris, September 1999.Google Scholar
Index Terms
How to keep your neighbours in order
Recommendations
Decidability of conversion for type theory in type theory
Type theory should be able to handle its own meta-theory, both to justify its foundational claims and to obtain a verified implementation. At the core of a type checker for intensional type theory lies an algorithm to check equality of types, or in ...
How to keep your neighbours in order
ICFP '14: Proceedings of the 19th ACM SIGPLAN international conference on Functional programmingI present a datatype-generic treatment of recursive container types whose elements are guaranteed to be stored in increasing order, with the ordering invariant rolled out systematically. Intervals, lists and binary search trees are instances of the ...
Arity-generic datatype-generic programming
PLPV '10: Proceedings of the 4th ACM SIGPLAN workshop on Programming languages meets program verificationSome programs are doubly-generic. For example, map is datatype-generic in that many different data structures support a mapping operation. A generic programming language like Generic Haskell can use a single definition to generate map for each type. ...







Comments