skip to main content
research-article

How to keep your neighbours in order

Published:19 August 2014Publication History
Skip Abstract Section

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.

References

  1. William Aitken and John Reppy. Abstract value constructors. Technical Report TR 92-1290, Cornell University, 1992.Google ScholarGoogle Scholar
  2. Robert Atkey, Patricia Johann, and Neil Ghani. Refining inductive types. Logical Methods in Computer Science, 8 (2), 2012.Google ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. Rod Burstall. Proving properties of programs by structural induction. Computer Journal, 12 (1): 41--48, 1969.Google ScholarGoogle ScholarCross RefCross Ref
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. Gérard P. Huet. The zipper. J. Funct. Program., 7 (5): 549--554, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. Stefan Kahrs. Red-black trees with types. J. Funct. Program., 11 (4): 425--432, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. Conor McBride. A Case For Dependent Families. LFCS Theory Seminar, Edinburgh, 2000. URL http://strictlypositive.org/a-case/.Google ScholarGoogle Scholar
  13. Conor McBride and James McKinna. The view from the left. J. Funct. Program., 14 (1): 69--111, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Conor McBride and Ross Paterson. Applicative programming with effects. J. Funct. Program., 18 (1): 1--13, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Matthew Might. The missing method: Deleting from Okasaki's red-black trees. Blog post, 2010. http://matt.might.net/articles/red-black-delete/.Google ScholarGoogle Scholar
  16. Robin Milner. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17 (3): 348--375, 1978.Google ScholarGoogle ScholarCross RefCross Ref
  17. David Turner. Elementary strong functional programming. 1987. URL http://sblp2004.ic.uff.br/papers/turner.pdf.Google ScholarGoogle Scholar
  18. Philip Wadler. The concatenate vanishes. Technical report, 1987.Google ScholarGoogle Scholar
  19. 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 ScholarGoogle Scholar

Index Terms

  1. How to keep your neighbours in order

      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

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 49, Issue 9
        ICFP '14
        September 2014
        361 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2692915
        Issue’s Table of Contents
        • cover image ACM Conferences
          ICFP '14: Proceedings of the 19th ACM SIGPLAN international conference on Functional programming
          August 2014
          390 pages
          ISBN:9781450328739
          DOI:10.1145/2628136

        Copyright © 2014 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 19 August 2014

        Check for updates

        Qualifiers

        • research-article

      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!