skip to main content
research-article

A typechecker plugin for units of measure: domain-specific constraint solving in GHC Haskell

Published:30 August 2015Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle Scholar
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A typechecker plugin for units of measure: domain-specific constraint solving in GHC Haskell

      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 50, Issue 12
        Haskell '15
        December 2015
        212 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2887747
        Issue’s Table of Contents
        • cover image ACM Conferences
          Haskell '15: Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell
          August 2015
          212 pages
          ISBN:9781450338080
          DOI:10.1145/2804302

        Copyright © 2015 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 30 August 2015

        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!