skip to main content
research-article

Dependently typed programming with singletons

Published:13 September 2012Publication History
Skip Abstract Section

Abstract

Haskell programmers have been experimenting with dependent types for at least a decade, using clever encodings that push the limits of the Haskell type system. However, the cleverness of these encodings is also their main drawback. Although the ideas are inspired by dependently typed programs, the code looks significantly different. As a result, GHC implementors have responded with extensions to Haskell's type system, such as GADTs, type families, and datatype promotion. However, there remains a significant difference between programming in Haskell and in full-spectrum dependently typed languages. Haskell enforces a phase separation between runtime values and compile-time types. Therefore, singleton types are necessary to express the dependency between values and types. These singleton types introduce overhead and redundancy for the programmer.

This paper presents the singletons library, which generates the boilerplate code necessary for dependently typed programming using GHC. To compare with full-spectrum languages, we present an extended example based on an Agda interface for safe database access. The paper concludes with a detailed discussion on the current capabilities of GHC for dependently typed programming and suggestions for future extensions to better support this style of programming.

References

  1. L. Augustsson. Cayenne - a language with dependent types. In Proc. ACM SIGPLAN International Conference on Functional Programming, ICFP '98, pages 239--250. ACM, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. I. Baars and S. D. Swierstra. Typing dynamic typing. In Proc. 7th ACM SIGPLAN International Conference on Functional Programming, ICFP '02, pages 157--166. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. J.-P. Bernardy, P. Jansson, and R. Paterson. Parametricity and dependent types. In Proc. 15th ACM SIGPLAN International Conference on Functional Programming, ICFP '10, pages 345--356. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. R. S. Bird and R. Paterson. de Bruijn notation as a nested datatype. J. Funct. Program., 9(1):77--91, Jan. 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. B. Bringert, A. Höckersten, C. Andersson, M. Andersson, M. Bergman, V. Blomqvist, and T. Martin. Student paper: HaskellDB improved. In Proc. 2004 ACM SIGPLAN workshop on Haskell, Haskell '04, pages 108--115. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. J. Carette, O. Kiselyov, and C.-c. Shan. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program., 19(5):509--543, Sept. 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. C. Casinghino, V. Sjöberg, and S. Weirich. Step-indexed normalization for a language with general recursion. In Proc. 4th Workshop on Mathematically Structured Functional Programming, Tallinn, Estonia, pages 25--39, 2012.Google ScholarGoogle ScholarCross RefCross Ref
  8. M. M. T. Chakravarty, G. Keller, and S. Peyon Jones. Associated type synonyms. In Proc. 10th ACM SIGPLAN International Conference on Functional Programming, ICFP '05, pages 241--253. ACM, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. C. Chen and H. Xi. Combining programming with theorem proving. In Proc. 10th ACM SIGPLAN International Conference on Functional Programming, ICFP '05, pages 66--77. ACM, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Cheney and R. Hinze. A lightweight implementation of generics and dynamics. In Proc. 2002 ACM SIGPLAN workshop on Haskell, Haskell '02, pages 90--104. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. J. Condit, M. Harren, Z. Anderson, D. Gay, and G. C. Necula. Dependent types for low-level programming. In Proc. 16th European conference on Programming, ESOP'07, pages 520--535. Berlin, Heidelberg, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Coq development team. The Coq proof assistant reference manual. LogiCal Project, 2004. URL http://coq.inria.fr. Version 8.0.Google ScholarGoogle Scholar
  13. K. Crary and S. Weirich. Resource bound certification. In Proc. 27th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, POPL '00, pages 184--198. ACM, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. D. Dreyer, R. Harper, M. M. T. Chakravarty, and G. Keller. Modular type classes. In Proc. 34th annual ACM SIGPLAN-SIGACT symposium on Principles of Programming Languages, POPL '07, pages 63--70. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. J. Giesl, M. Raffelsieper, P. Schneider-Kamp, S. Swiderski, and R. Thiemann. Automated termination proofs for Haskell by term rewriting. ACM Trans. Program. Lang. Syst., 33(2):7:1--7:39, Feb. 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. L.-J. Guillemette and S. Monnier. A type-preserving compiler in Haskell. In Proc. 13th ACM SIGPLAN International Conference on Functional Programming, ICFP '08, pages 75--86. ACM, 2008a. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. L.-J. Guillemette and S. Monnier. One vote for type families in Haskell! In Proc. 9th Symposium on Trends in Functional Programming, 2008b.Google ScholarGoogle Scholar
  18. S. Hayashi. Singleton, union and intersection types for program extraction. In Proc. International Conference on Theoretical Aspects of Computer Software, TACS '91, pages 701--730. Springer-Verlag, London, UK, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. W. Kahl and J. Scheffczyk. Named instances for Haskell type classes. In Proc. 2001 ACM SIGPLAN Workshop on Haskell, Haskell '01, pages 71--99. ACM, 2001. See also: http://ist.unibw-muenchen.de/Haskell/NamedInstances/.Google ScholarGoogle Scholar
  20. O. Kiselyov and C.-c. Shan. Lightweight static capabilities. Electron. Notes Theor. Comput. Sci., 174(7):79--104, June 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. O. Kiselyov, R. Lämmel, and K. Schupke. Strongly typed heterogeneous collections. In Proc. 2004 ACM SIGPLAN Workshop on Haskell, Haskell '04, pages 96--107. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. D. Leijen and E. Meijer. Domain specific embedded compilers. In Proc. 2nd conference on Domain-Specific Languages, DSL '99, pages 109--122. ACM, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. J. R. Lewis, J. Launchbury, E. Meijer, and M. B. Shields. Implicit parameters: dynamic scoping with static types. In Proc. 27th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, POPL '00, pages 108--118. ACM, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. J. P. Magalhães. The right kind of generic programming. To appear at WGP, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. C. McBride. Faking it simulating dependent types in Haskell. J. Funct. Program., 12(5):375--392, July 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. C. McBride. Epigram, 2004. http://www.dur.ac.uk/CARG/epigram.Google ScholarGoogle Scholar
  27. S. Monnier and D. Haguenauer. Singleton types here, singleton types there, singleton types everywhere. In Proc. 4th ACM SIGPLAN workshop on Programming languages meets program verification, PLPV '10, pages 1--8. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. M. Neubauer and P. Thiemann. Type classes with more higher-order polymorphism. In Proc. 7th ACM SIGPLAN International Conference on Functional Programming, ICFP '02, pages 179--190. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Department of Computer Science and Engineering, Chalmers University of Technology, SE-412 96 Göoteborg, Sweden, September 2007.Google ScholarGoogle Scholar
  30. C. Okasaki. From fast exponentiation to square matrices: an adventure in types. In Proc. 4th ACM SIGPLAN International Conference on Functional Programming, ICFP '99, pages 28--35. ACM, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. N. Oury and W. Swierstra. The power of Pi. In Proc. 13th ACM SIGPLAN international conference on Functional programming, ICFP '08, pages 39--50. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. S. Peyton Jones, D. Vytiniotis, S. Weirich, and G. Washburn. Simple unification-based type inference for GADTs. In Proc. 11th ACM SIGPLAN International Conference on Functional Programming, ICFP '06, pages 50--61. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. T. Schrijvers, S. Peyton Jones, M. Sulzmann, and D. Vytiniotis. Complete and decidable type inference for GADTs. In Proc. 14th ACM SIGPLAN international conference on Functional programming, ICFP '09, pages 341--352. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. T. Sheard and S. Peyton Jones. Template meta-programming for Haskell. In Proc. 2002 ACM SIGPLAN workshop on Haskell, Haskell '02, pages 1--16. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. T. Sheard, J. Hook, and N. Linger. GADTs + extensible kind system = dependent programming. Technical report, Portland State University, 2005. http://www.cs.pdx.edu/~sheard.Google ScholarGoogle Scholar
  36. N. Swamy, J. Chen, C. Fournet, P.-Y. Strub, K. Bhargavan, and J. Yang. Secure distributed programming with value-dependent types. In Proc. 16th ACM SIGPLAN International Conference on Functional Programming, ICFP '11, pages 266--278. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. D. Vytiniotis, S. Peyton Jones, and J. P. Magalhães. Equality proofs and deferred type errors: A compiler pearl. To appear at ICFP, 2012. S. Weirich. Type-safe cast: Functional pearl. J. Funct. Program., 14(6): 681--695, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. S. Weirich, J. Hsu, and R. A. Eisenberg. Down with kinds: adding dependent heterogeneous equality to FC (extended version). Technical report, University of Pennsylvania, 2012. URL http://www.cis.upenn.edu/~sweirich/papers/nokinds-extended.pdf.Google ScholarGoogle Scholar
  39. H. Xi and F. Pfenning. Eliminating array bound checking through dependent types. In Proc. ACM SIGPLAN 1998 conference on Programming language design and implementation, PLDI '98, pages 249--257. ACM, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. H. Xi and F. Pfenning. Dependent types in practical programming. In Proc. 26th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, POPL '99, pages 214--227. ACM, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. H. Xi, C. Chen, and G. Chen. Guarded recursive datatype constructors. In Proc. 30th ACM SIGPLAN-SIGACT symposium on Principles of Programming Languages, POPL '03, pages 224--235. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. B. A. Yorgey, S. Weirich, J. Cretin, S. Peyton Jones, D. Vytiniotis, and J. P. Magalhães. Giving Haskell a promotion. In Proc. 8th ACM SIGPLAN workshop on Types in Language Design and Implementation, TLDI '12, pages 53--66. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Dependently typed programming with singletons

        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 12
          Haskell '12
          December 2012
          157 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2430532
          Issue’s Table of Contents
          • cover image ACM Conferences
            Haskell '12: Proceedings of the 2012 Haskell Symposium
            September 2012
            168 pages
            ISBN:9781450315746
            DOI:10.1145/2364506

          Copyright © 2012 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 13 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!