skip to main content
research-article

Transporting functions across ornaments

Published:09 September 2012Publication History
Skip Abstract Section

Abstract

Programming with dependent types is a blessing and a curse. It is a blessing to be able to bake invariants into the definition of datatypes: we can finally write correct-by-construction software. However, this extreme accuracy is also a curse: a datatype is the combination of a structuring medium together with a special purpose logic. These domain-specific logics hamper any effort of code reuse among similarly structured data. In this paper, we exorcise our datatypes by adapting the notion of ornament to our universe of inductive families. We then show how code reuse can be achieved by ornamenting functions. Using these functional ornaments, we capture the relationship between functions such as the addition of natural numbers and the concatenation of lists. With this knowledge, we demonstrate how the implementation of the former informs the implementation of the latter: the user can ask the definition of addition to be lifted to lists and she will only be asked the details necessary to carry on adding lists rather than numbers. Our presentation is formalised in a type theory with a universe of datatypes and all our constructions have been implemented as generic programs, requiring no extension to the type theory.

References

  1. R. Atkey, P. Johann, and N. Ghani. When is a type refinement an inductive type? In phFOSSACS, volume 6604 of phLecture Notes in Computer Science, pages 72--87. Springer, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. J.-P. Bernardy and M. Lasson. Realizability and parametricity in pure type systems. In phFOSSACS, volume 6604 of phLecture Notes in Computer Science, pages 108--122. Springer, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. R. S. Bird and O. de Moor. phAlgebra of programming. Prentice Hall, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. E. Brady, C. McBride, and J. McKinna. Inductive families need not store their indices. In phTypes for Proofs and Programs, pages 115--129. 2004.Google ScholarGoogle Scholar
  5. J. Chapman, P.-E. Dagand, C. McBride, and P. Morris. The gentle art of levitation. phSIGPLAN Not., 45: 3--14, September 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. T. Coquand. Pattern matching with dependent types. In phTypes for Proofs and Programs, 1992.Google ScholarGoogle Scholar
  7. P. Dybjer. Inductive families. phFormal Asp. Comput., 6 (4): 440--465, 1994.Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. T. Freeman and F. Pfenning. Refinement types for ML. phSIGPLAN Not., 26: 268--277, May 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. C. Fumex, N. Ghani, and P. Johann. Indexed induction and coinduction, fibrationally. In phCALCO, pages 176--191, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. R. Harper and C. Stone. A Type-Theoretic interpretation of standard ML. In phProof, Language, and Interaction: essays in honour of Robin Milner, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. H.-S. Ko and J. Gibbons. Modularising inductive families. In phWorkshop on Generic Programming, pages 13--24, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. C. McBride. Ornamental algebras, algebraic ornaments. phJournal of Functional Programming, to appear, 2012.Google ScholarGoogle Scholar
  13. C. McBride and J. McKinna. The view from the left. phJ. Funct. Program., 14 (1): 69--111, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. C. McBride, H. Goguen, and J. McKinna. A few constructions on constructors. In phTYPES, pages 186--200, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. P. Morris, T. Altenkirch, and N. Ghani. A universe of strictly positive families. phInt. J. Found. Comput. Sci., 20 (1): 83--107, 2009.Google ScholarGoogle ScholarCross RefCross Ref
  16. U. Norell. phTowards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology, 2007.Google ScholarGoogle Scholar
  17. P.-Y. Strub. Coq modulo theory. In phCSL, pages 529--543, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. N. Swamy, J. Chen, C. Fournet, P.-Y. Strub, K. Bhargavan, and J. Yang. Secure distributed programming with value-dependent types. In phICFP, pages 266--278. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. }coq:manualThe Coq Development Team. phThe Coq Proof Assistant Reference Manual.Google ScholarGoogle Scholar
  20. H. Xi, C. Chen, and G. Chen. Guarded recursive datatype constructors. In phPOPL, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Transporting functions across ornaments

    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 47, Issue 9
      ICFP '12
      September 2012
      368 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2398856
      Issue’s Table of Contents
      • cover image ACM Conferences
        ICFP '12: Proceedings of the 17th ACM SIGPLAN international conference on Functional programming
        September 2012
        392 pages
        ISBN:9781450310543
        DOI:10.1145/2364527

      Copyright © 2012 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 9 September 2012

      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!