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.
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- R. S. Bird and R. Paterson. de Bruijn notation as a nested datatype. J. Funct. Program., 9(1):77--91, Jan. 1999. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Coq development team. The Coq proof assistant reference manual. LogiCal Project, 2004. URL http://coq.inria.fr. Version 8.0.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- L.-J. Guillemette and S. Monnier. One vote for type families in Haskell! In Proc. 9th Symposium on Trends in Functional Programming, 2008b.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- O. Kiselyov and C.-c. Shan. Lightweight static capabilities. Electron. Notes Theor. Comput. Sci., 174(7):79--104, June 2007. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- J. P. Magalhães. The right kind of generic programming. To appear at WGP, 2012. Google Scholar
Digital Library
- C. McBride. Faking it simulating dependent types in Haskell. J. Funct. Program., 12(5):375--392, July 2002. Google Scholar
Digital Library
- C. McBride. Epigram, 2004. http://www.dur.ac.uk/CARG/epigram.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Dependently typed programming with singletons
Recommendations
Dependently typed programming with singletons
Haskell '12: Proceedings of the 2012 Haskell SymposiumHaskell 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 ...
Strongly typed heterogeneous collections
Haskell '04: Proceedings of the 2004 ACM SIGPLAN workshop on HaskellA heterogeneous collection is a datatype that is capable of storing data of different types, while providing operations for look-up, update, iteration, and others. There are various kinds of heterogeneous collections, differing in representation, ...
Dependently typed programming in Agda
TLDI '09: Proceedings of the 4th international workshop on Types in language design and implementationDependently typed languages have for a long time been used to describe proofs about programs. Traditionally, dependent types are used mostly for stating and proving the properties of the programs and not in defining the programs themselves. An ...







Comments