Abstract
Typed functional programming and units of measure are a natural combination, as F# ably demonstrates. However, encoding statically-checked units in Haskell’s type system leads to inevitable disappointment with the usability of the resulting system. Extending the language itself would produce a much better result, but it would be a lot of work! In this paper, I demonstrate how typechecker plugins in the Glasgow Haskell Compiler allow users to define domain-specific constraint solving behaviour, making it possible to implement units of measure as a type system extension without rebuilding the compiler. This paves the way for a more modular treatment of constraint solving in GHC.
- Robert Atkey, Patricia Johann, and Andrew Kennedy. Abstraction and invariance for algebraically indexed types. In Proceedings of the 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’13, pages 87–100. ACM, 2013. Google Scholar
Digital Library
- Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones, and Stephanie Weirich. Safe zero-cost coercions for Haskell. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming, ICFP ’14, pages 189–202. ACM, 2014. Google Scholar
Digital Library
- David Raymond Christiansen. Reflect on your mistakes! Lightweight domain-specific error messages, 2014. URL http://www.itu.dk/ people/drc/drafts/error-reflection-submission.pdf. Iavor S. Diatchki. Improving Haskell types with SMT. In Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell, Haskell ’15. ACM, 2015. Google Scholar
Digital Library
- In press. Jacques Garrigue. Relaxing the value restriction. In Yukiyoshi Kameyama and Peter J. Stuckey, editors, Functional and Logic Programming, volume 2998 of LNCS, pages 196–213. Springer, 2004.Google Scholar
- Adam Gundry. Type Inference, Haskell and Dependent Types. PhD thesis, University of Strathclyde, 2013. URL http://adam.gundry.co.uk/ pub/thesis/. Andrew Kennedy. Programming Languages and Dimensions. PhD thesis, University of Cambridge, 1996. URL http://research.microsoft.com/en-us/um/people/akenn/ units/ProgrammingLanguagesAndDimensions.pdf. Andrew Kennedy. Types for units-of-measure: Theory and practice. In Zoltán Horváth, Rinus Plasmeijer, and Viktória Zsók, editors, Central European Functional Programming School, volume 6299 of LNCS, pages 268–305. Springer, 2010. Google Scholar
Digital Library
- Ralf Lämmel and Simon Peyton Jones. Scrap your boilerplate: A practical design pattern for generic programming. In Proceedings of the 2003 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation, TLDI ’03, pages 26–37. ACM, 2003. Google Scholar
Digital Library
- Daan Leijen and Erik Meijer. Domain specific embedded compilers. In Proceedings of the 2nd Conference on Domain-Specific Languages, DSL ’99, pages 109–122. ACM, 1999. Google Scholar
Digital Library
- Takayuki Muranushi and Richard A. Eisenberg. Experience report: Typechecking polymorphic units for astrophysics research in Haskell. In Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell ’14, pages 31–38. ACM, 2014. Google Scholar
Digital Library
- Dominic Orchard and Tomas Petricek. Embedding effect systems in Haskell. In Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell ’14, pages 13–24. ACM, 2014. Google Scholar
Digital Library
- Tom Schrijvers, Simon Peyton Jones, Manuel Chakravarty, and Martin Sulzmann. Type checking with open type functions. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, ICFP ’08, pages 51–62. ACM, 2008. Google Scholar
Digital Library
- Jan Stolarek, Simon Peyton Jones, and Richard A. Eisenberg. Injective type families for Haskell. In Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell, Haskell ’15. ACM, 2015. In press. Martin Sulzmann, Martin Müller, and Christoph Zenger. Hindley/Milner style type systems in constraint form. Res. Rep. ACRC-99-009, University of South Australia, School of Computer and Information Science, 1999. Google Scholar
Digital Library
- Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. System F with type equality coercions. In Proceedings of the 2007 ACM SIGPLAN International Workshop on Types in Language Design and Implementation, TLDI ’07, pages 53–66. ACM, 2007. Google Scholar
Digital Library
- Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon Peyton Jones. Refinement types for Haskell. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming, ICFP ’14, pages 269–282. ACM, 2014. Google Scholar
Digital Library
- Dimitrios Vytiniotis, Simon Peyton Jones, Tom Schrijvers, and Martin Sulzmann. OutsideIn(X): Modular type inference with local assumptions. Journal of Functional Programming, 21(4–5):333–412, 2011. Google Scholar
Digital Library
- Dimitrios Vytiniotis, Simon Peyton Jones, and José Pedro Magalhães. Equality proofs and deferred type errors: A compiler pearl. In Proceedings of the 17th ACM SIGPLAN International Conference on Functional Programming, ICFP ’12, pages 341–352. ACM, 2012. Google Scholar
Digital Library
- Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. Giving Haskell a promotion. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation, TLDI ’12, pages 53–66. ACM, 2012. Google Scholar
Digital Library
Index Terms
A typechecker plugin for units of measure: domain-specific constraint solving in GHC Haskell
Recommendations
A typechecker plugin for units of measure: domain-specific constraint solving in GHC Haskell
Haskell '15: Proceedings of the 2015 ACM SIGPLAN Symposium on HaskellTyped functional programming and units of measure are a natural combination, as F# ably demonstrates. However, encoding statically-checked units in Haskell’s type system leads to inevitable disappointment with the usability of the resulting system. ...
Interactive type debugging in Haskell
Haskell '03: Proceedings of the 2003 ACM SIGPLAN workshop on HaskellIn this paper we illustrate the facilities for type debugging of Haskell programs in the Chameleon programming environment. Chameleon provides an extension to Haskell supporting advanced and programmable type extensions. Chameleon maps the typing ...
Dependently-Typed programming in GHC
FLOPS'12: Proceedings of the 11th international conference on Functional and Logic ProgrammingIs Haskell a dependently-typed programming language?
The Glasgow Haskell Compiler (GHC) type-system extensions, such as Generalized Algebraic Datatypes (GADTs), multiparameter type classes and type families, give programmers the ability to encode domain-...






Comments