Abstract
Type family applications in Haskell must be fully saturated. This means that all type-level functions have to be first-order, leading to code that is both messy and longwinded. In this paper we detail an extension to GHC that removes this restriction. We augment Haskell’s existing type arrow, |->|, with an unmatchable arrow, | >|, that supports partial application of type families without compromising soundness. A soundness proof is provided. We show how the techniques described can lead to substantial code-size reduction (circa 80%) in the type-level logic of commonly-used type-level libraries whilst simultaneously improving code quality and readability.
Supplemental Material
- Thorsten Altenkirch, Conor McBride, and Peter Morris. 2006. Generic programming with dependent types. In International Spring School on Datatype-Generic Programming. Springer, 209–257.Google Scholar
- Maximilian C. Bolingbroke. 2011. Constraint Kinds for GHC. http://blog.omega- prime.co.uk/2011/09/10/constraint- kindsfor- ghc/Google Scholar
- Edwin Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. J. Funct. Prog. 23 (2013).Google Scholar
- Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. 2005. Associated Type Synonyms. In International Conference on Functional Programming (ICFP ’05). ACM. Google Scholar
Digital Library
- Richard A Eisenberg. 2016. Dependent types in Haskell: Theory and Practice. Ph.D. Dissertation. University of Pennsylvania.Google Scholar
- Richard A Eisenberg and Simon Peyton Jones. 2017. Levity polymorphism. In ACM SIGPLAN Notices, Vol. 52. ACM, 525–539. Google Scholar
Digital Library
- Richard A. Eisenberg and Jan Stolarek. 2014. Promoting Functions to Type Families in Haskell. In ACM SIGPLAN Haskell Symposium. Google Scholar
Digital Library
- Richard A. Eisenberg, Dimitrios Vytiniotis, Simon Peyton Jones, and Stephanie Weirich. 2014. Closed Type Families with Overlapping Equations. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’14). ACM, New York, NY, USA, 671–683. Google Scholar
Digital Library
- Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application. In ESOP. Google Scholar
Digital Library
- GHC. 2019. GHC User Manual on Type Families. https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ glasgow_exts.html#type- families Accessed: 2019-05-31.Google Scholar
- Adam Gundry. 2013. Type Inference, Haskell and Dependent Types. Ph.D. Dissertation. University of Strathclyde.Google Scholar
- Gerard P Huet. 1973. The undecidability of unification in third order logic. Information and Control 22, 3 (1973), 257–267.Google Scholar
Cross Ref
- Chung-Kil Hur. 2010. Agda with the excluded middle is inconsistent? https://coq- club.inria.narkive.com/iDuSeltD/agdawith- the- excluded- middle- is- inconsistent . Accessed: 2019-03-01.Google Scholar
- Oleg Kiselyov, Ralf Lämmel, and Keean Schupke. 2004. Strongly typed heterogeneous collections. In Proc. 2004 ACM SIGPLAN Workshop on Haskell (Haskell ’04). ACM, 96–107. Google Scholar
Digital Library
- Csongor Kiss, Matthew Pickering, and Nicolas Wu. 2018. Generic Deriving of Generic Traversals. In International Conference on Functional Programming (ICFP ’18). ACM. arXiv: arXiv:1805.06798Google Scholar
- Ralf Lämmel and Simon Peyton Jones. 2003. Scrap Your Boilerplate: A Practical Design Pattern for Generic Programming. In Types in Languages Design and Implementation. ACM Press, New York, NY, USA, 26–37. Google Scholar
Digital Library
- José Pedro Magalhães, Atze Dijkstra, Johan Jeuring, and Andres Löh. 2010. A Generic Deriving Mechanism for Haskell. In Proceedings of the Third ACM Haskell Symposium on Haskell (Haskell ’10). ACM, New York, NY, USA, 37–48. Google Scholar
Digital Library
- Dale Miller. 1992. Unification under a mixed prefix. Journal of symbolic computation 14, 4 (1992), 321–358. Google Scholar
Digital Library
- My Nguyen. 2018. Type-level visible type application. Talk, Haskell Implementors Workshop, St. Louis, MO, United States.Google Scholar
- Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph.D. Dissertation. Department of Computer Science and Engineering, Chalmers University of Technology, SE-412 96 Göteborg, Sweden.Google Scholar
- John Reynolds. 1972. Definitional Interpreters for Higher-Order Programming Languages. In ACM Annual Conference. Google Scholar
Digital Library
- Tim Sheard and Simon Peyton Jones. 2002. Template meta-programming for Haskell. In Proc. 2002 ACM SIGPLAN workshop on Haskell (Haskell ’02). ACM, 1–16. Google Scholar
Digital Library
- Vincent Simonet and François Pottier. 2007. A Constraint-based Approach to Guarded Algebraic Data Types. ACM Trans. Program. Lang. Syst. 29, 1, Article 1 (Jan. 2007). Google Scholar
Digital Library
- Jan Stolarek, Simon Peyton Jones, and Richard A. Eisenberg. 2015. Injective Type Families for Haskell. In Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell (Haskell ’15). ACM, New York, NY, USA, 118–128. Google Scholar
Digital Library
- Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. 2007. System F with type equality coercions. In Types in languages design and implementation (TLDI ’07). ACM. Google Scholar
Digital Library
- Anish Tondwalkar. 2018. Popularity of Haskell Extensions. https://gist.github.com/atondwal/ ee869b951b5cf9b6653f7deda0b7dbd8 . Accessed: 2019-02-24.Google Scholar
- Dimitrios Vytiniotis, Simon Peyton Jones, Tom Schrijvers, and Martin Sulzmann. 2011. OutsideIn(X): Modular Type Inference with Local Assumptions. Journal of Functional Programming 21, 4-5 (Sept. 2011). Google Scholar
Digital Library
- Stephanie Weirich, Justin Hsu, and Richard A. Eisenberg. 2013. System FC with Explicit Kind Equality. In International Conference on Functional Programming (ICFP ’13). ACM. Google Scholar
Digital Library
- Stephanie Weirich, Antoine Voizard, Pedro Henrique Azevedo de Amorim, and Richard A. Eisenberg. 2017. A Specification for Dependent Types in Haskell. Proc. ACM Program. Lang. 1, ICFP, Article 31 (Aug. 2017), 29 pages. Google Scholar
Digital Library
- Stephanie Weirich, Dimitrios Vytiniotis, Simon Peyton Jones, and Steve Zdancewic. 2011. Generative type abstraction and type-level computation. In POPL. ACM. Google Scholar
Digital Library
- Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded recursive datatype constructors. In Principles of Programming Languages (POPL ’03). ACM. Google Scholar
Digital Library
- Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. 2012. Giving Haskell a promotion. In Types in Language Design and Implementation (TLDI ’12). ACM. Google Scholar
Digital Library
Index Terms
Higher-order type-level programming in Haskell
Recommendations
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...
Type Class Instances for Type-Level Lambdas in Haskell
TFP 2015: Revised Selected Papers of the 16th International Symposium on Trends in Functional Programming - Volume 9547Haskell 2010 lacks flexibility in creating instances of type classes for type constructors with multiple type arguments. We would like to make the order of type arguments to a type constructor irrelevant to how type class instances can be specified. ...






Comments