skip to main content
research-article

Names for free: polymorphic views of names and binders

Published:23 September 2013Publication History
Skip Abstract Section

Abstract

We propose a novel technique to represent names and binders in Haskell. The dynamic (run-time) representation is based on de Bruijn indices, but it features an interface to write and manipulate variables conviently, using Haskell-level lambdas and variables. The key idea is to use rich types: a subterm with an additional free variable is viewed either as forallν.ν → Term(ɑ + ν) or ϶ν.ν x Term(ν.ν) depending on whether it is constructed or analysed. We demonstrate on a number of examples how this approach permits to express term construction and manipulation in a natural way, while retaining the good properties of representations based on de Bruijn indices.

References

  1. T. Altenkirch. A formalization of the strong normalization proof for System F in LEGO. In J. G. M. Bezem, editor, Typed Lambda Calculi and Applications, LNCS 664, pages 13--28, 1993. URL http://www.cs.nott.ac.uk/txa/publ/tlca93.pdf. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. T. Altenkirch and B. Reus. Monadic presentations of lambda terms using generalized inductive types. In Computer Science Logic, volume 1683 of Lecture Notes in Computer Science, pages 453--468. Springer, 1999. URL http://www.cs.nott.ac.uk/txa/publ/csl99.pdf. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. S. Ambler, R. L. Crole, and A. Momigliano. Combining higher order abstract syntax with tactical theorem proving and (co)induction. In Proceedings of the 15th International Conference on Theorem Proving in Higher Order Logics, TPHOLs '02, pages 13--30, London, UK, UK, 2002. Springer-Verlag. ISBN 3-540-44039-9. URL http://dl.acm.org/citation.cfm?id=646529.695204. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. R. Atkey. Syntax for free: representing syntax with binding using parametricity. In International Conference on Typed Lambda Calculi and Applications (TLCA), volume 5608 of Lecture Notes in Computer Science, pages 35--49. Springer, July 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. F. Bellegarde and J. Hook. Substitution: A formal methods case study using monads and transformations. Sci. Comput. Program., 23 (2--3): 287--311, 1994. http://dx.doi.org/10.1016/0167-6423(94)00022-0. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. J.-P. Bernardy and G. Moulin. A computational interpretation of parametricity. In Proceedings of the Symposium on Logic in Computer Science. IEEE Computer Society, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. J.-P. Bernardy and G. Moulin. Type-theory in color. In Proceeding of the 18th ACM SIGPLAN international conference on Functional Programming, 2013. To appear. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. J.-P. Bernardy, P. Jansson, and R. Paterson. Proofs for free -- parametricity for dependent types. Journal of Functional Programming, 22 (02): 107--152, 2012. 10.1017/S0956796812000056. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. R. Bird and R. Paterson. de Bruijn notation as a nested datatype. Journal of Functional Programming, 9 (1): 77--91, Jan. 1999. URL http://dx.doi.org/10.1017/S0956796899003366. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. V. Capretta and A. P. Felty. Combining de bruijn indices and higher-order abstract syntax in coq. In Proceedings of the 2006 international conference on Types for proofs and programs, TYPES'06, pages 63--77, Berlin, Heidelberg, 2007. Springer-Verlag. ISBN 3-540-74463-0, 978-3-540-74463-4. URL http://dl.acm.org/citation.cfm?id=1789277.1789282. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. A. Chlipala. Parametric higher-order abstract syntax for mechanized semantics. In phProceedings of the 13th ACM SIGPLAN international conference on Functional programming, pages 143--156, New York, NY, USA, 2008. ACM. ISBN 978--1--59593--919--7. http://doi.acm.org/10.1145/1411204.1411226. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. 972)}de_bruijn_lambda_1972N. G. de Bruijn. Lambda calculus notation with nameless dummies. In phIndagationes Mathematicae, volume 34. Elsevier, 1972.Google ScholarGoogle Scholar
  13. L. Fegaras and T. Sheard. Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space). In phProceedings of the 23rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 284--294, St. Petersburg Beach, Florida, United States, 1996. ACM. ISBN 0--89791--769--3. 10.1145/237721.237792. URL http://portal.acm.org/citation.cfm?id=237792. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. L.-J. Guillemette and S. Monnier. A type-preserving closure conversion in haskell. In phProceedings of the ACM SIGPLAN workshop on Haskell, pages 83--92. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. L.-J. Guillemette and S. Monnier. A type-preserving compiler in haskell. In Proceedings of the 13th ACM SIGPLAN international conference on Functional Programming, pages 75--86. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. C. Keller and M. Lasson. Parametricity in an impredicative sort. In CSL, pages 381--395, 2012.Google ScholarGoogle Scholar
  17. E. Kmett. Bound: Making de Bruijn Succ less, 2012. URL http://hackage.haskell.org/package/bound. Haskell package.Google ScholarGoogle Scholar
  18. C. McBride. I am not a number, i am a classy hack, 2010. URL http://www.e-pig.org/epilogue/?p=773. Weblog entry.Google ScholarGoogle Scholar
  19. C. McBride and J. McKinna. The view from the left. phJ. Funct. Program., 14: 69--111, January 2004. ISSN 0956--7968. 10.1017/S0956796803004829. URL http://www.cs.ru.nl/ james/RESEARCH/view-final2004.pdf. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. nd Paterson(2007)}mcbride_applicative_2007C. McBride and R. Paterson. Applicative programming with effects. phJournal of Functional Programming, 18 (01): 1--13, 2007. 10.1017/S0956796807006326. URL http://www.journals.cambridge.org/abstract\_S0956796807006326. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. D. A. Miller and A. F. Tiu. A proof theory for generic judgments: An extended abstract. In phProceedings of the 18th Annual IEEE Symposium on Logic in Computer Science, pages 118--127. IEEE Computer Society, June 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. A. Nanevski, F. Pfenning, and B. Pientka. Contextual modal type theory. phACM Trans. Comput. Logic, 9 (3): 23:1--23:49, June 2008. ISSN 1529--3785. 10.1145/1352582.1352591. URL http://doi.acm.org/10.1145/1352582.1352591. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. N. Pouillard and F. Pottier. A unified treatment of syntax with binders. phJournal of Functional Programming, 22 (4--5): 614--704, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. J. C. Reynolds. Types, abstraction and parametric polymorphism. In phInformation Processing 83, pages 513--523. Elsevier Science, 1983. URL ftp://ftp.cs.cmu.edu/user/jcr/typesabpara.pdf.Google ScholarGoogle Scholar
  25. G. Washburn and S. Weirich. Boxes go bananas: encoding higher-order abstract syntax with parametric polymorphism. In phProceedings of the eighth ACM SIGPLAN international conference on Functional programming, pages 249--262, Uppsala, Sweden, 2003. ACM. ISBN 1--58113--756--7. 10.1145/944705.944728. URL http://portal.acm.org/citation.cfm?id=944728. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Names for free: polymorphic views of names and binders

    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 48, Issue 12
      Haskell '13
      December 2013
      149 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2578854
      Issue’s Table of Contents
      • cover image ACM Conferences
        Haskell '13: Proceedings of the 2013 ACM SIGPLAN symposium on Haskell
        September 2013
        158 pages
        ISBN:9781450323833
        DOI:10.1145/2503778

      Copyright © 2013 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 23 September 2013

      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!