Type Error Diagnosis for Embedded DSLs by Two-Stage Specialized Type Rules

Part of the Lecture Notes in Computer Science book series (LNCS, volume 9632)

Abstract

In the functional programming world, it is common to embed a domain specific language (DSL) in a general purpose language. Unfortunately, the extra abstraction layer provided by the DSL is lost when a type error occurs, and internals leak to users of the DSL.

This paper presents specialized type rules, a way to influence which part of the program is blamed and how the particular error message is worded. These type rules match part of the programming language abstract syntax tree (AST) and guide the type checker in order to provide custom diagnostics. Our goal is to enable DSL writers to keep their high-level abstractions throughout the whole development experience. Specialized type rules have already been considered in the literature: we enhance them by providing a mechanism to allow type rules to depend on partial type information.

The technique presented in this paper can be readily applied to any type engine which uses constraints to perform its duty. We refine the workings of the type engine by including a second gathering pass in case an error is found. In that second pass, partial type information can be used to select a type rule. In particular, we have implemented our techniques in a type engine based on the OutsideIn(X) framework, which underlies the Haskell GHC compiler since version 7.

References

  1. 1.
    Bailey, J., Stuckey, P.J.: Discovery of minimal unsatisfiable subsets of constraints using hitting set dualization. In: Hermenegildo, M.V., Cabeza, D. (eds.) PADL 2004. LNCS, vol. 3350, pp. 174–186. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  2. 2.
    Christiansen, D.R.: Reflect on Your Mistakes!. Lightweight Domain-Specific Error Messages, Presented at TFP (2014)Google Scholar
  3. 3.
    Damas, L., Milner, R.: Principal type-schemes for functional programs. In: Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1982, NY, USA, pp. 207–212. ACM, New York (1982)Google Scholar
  4. 4.
  5. 5.
    Giorgidze, G., Grust, T., Schweinsberg, N., Weijers, J.: Bringing back monad comprehensions. In: Proceedings of the 4th ACM Symposium on Haskell, Haskell 2011, NY, USA, pp. 13–22. ACM, New York (2011)Google Scholar
  6. 6.
    Gundry, A.: A typechecker plugin for units of measure: domain-specific constraint solving in GHC haskell. In: Proceedings of the 8th ACM SIGPLAN Symposium on Haskell, Haskell 2015, NY, USA, pp. 11–22. ACM, New York (2015)Google Scholar
  7. 7.
    Haack, C., Wells, J.B.: Type error slicing in implicitly typed higher-order languages. Sci. Comput. Program. 50(1–3), 189–224 (2004)MathSciNetCrossRefMATHGoogle Scholar
  8. 8.
    Hage, J., Heeren, B.: Heuristics for type error discovery and recovery. In: Horváth, Z., Zsók, V., Butterfield, A. (eds.) IFL 2006. LNCS, vol. 4449, pp. 199–216. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  9. 9.
    Hage, J., Heeren, B.: Strategies for solving constraints in type and effect systems. Electron. Notes Theor. Comput. Sci. 236, 163–183 (2009)CrossRefGoogle Scholar
  10. 10.
    Heeren, B., Hage, J.: Type class directives. In: Hermenegildo, M.V., Cabeza, D. (eds.) PADL 2004. LNCS, vol. 3350, pp. 253–267. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  11. 11.
    Heeren, B., Hage, J., Swierstra, S.D.: Scripting the type inference process. In: Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming, ICFP 2003, NY, USA, pp. 3–13. ACM, New York (2003)Google Scholar
  12. 12.
    Heeren, B., Leijen, D., van IJzendoorn, A.: Helium, for learning Haskell. In: Proceedings of the 2003 ACM SIGPLAN Workshop on Haskell, Haskell 2003, NY, USA, pp. 62–71. ACM, New York (2003)Google Scholar
  13. 13.
    Heeren, B.J.: Top Quality Type Error Messages. Ph.D. thesis, Universiteit Utrecht, The Netherlands, September 2005Google Scholar
  14. 14.
    Hudak, P.: Building domain-specific embedded languages. ACM Comput. Surv. 28(4es), Article No. 196 (1996). http://dl.acm.org/citation.cfm?id=242477
  15. 15.
    Koops, H.V., Magalhães, J.P., De Haas, W.B.: A functional approach to automatic melody harmonisation. In: Proceedings of the First ACM SIGPLAN Workshop on Functional Art, Music, Modeling & Design, FARM 2013, pp. 47–58. ACM (2013)Google Scholar
  16. 16.
    Lee, O., Yi, K.: Proofs about a folklore let-polymorphic type inference algorithm. ACM Trans. Program. Lang. Syst. 20(4), 707–723 (1998)CrossRefGoogle Scholar
  17. 17.
    Lorenzen, F., Erdweg, S.: Modular and automated type-soundness verification for language extensions. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, NY, USA, pp. 331–342. ACM, New York (2013)Google Scholar
  18. 18.
    Marceau, G., Fisler, K., Krishnamurthi, S.: Mind your language: on novices’ interactions with error messages. In: Proceedings of the 10th SIGPLAN Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, Onward! 2011, NY, USA, pp. 3–18. ACM, New York (2011)Google Scholar
  19. 19.
    McAdam, B.J.: On the unification of substitutions in type inference. In: Hammond, K., Davie, T., Clack, C. (eds.) IFL 1998. LNCS, vol. 1595, pp. 137–152. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  20. 20.
    Plociniczak, H., Miller, H., Odersky, M.: Improving human-compiler interaction through customizable type feedback (2014)Google Scholar
  21. 21.
    Pottier, F., Rémy, D.: The essence of ML type inference. In: Pierce, B.C. (ed.) Advanced Topics in Types and Programming Languages, chapter 10, pp. 389–489. MIT Press, Cambridge (2004). http://dl.acm.org/citation.cfm?id=1076265 Google Scholar
  22. 22.
    Serrano, A., Hage, J.: Specialized type rules in Cobalt. Technical report, Department of Information and Computing Sciences, Utrecht University (2015)Google Scholar
  23. 23.
    Snoyman, M.: Developing Web Applications with Haskell and Yesod. O’Reilly Media Inc, USA (2012)Google Scholar
  24. 24.
    Taha, W.: Plenary talk III domain-specific languages. In: ICCES 2008, International Conference on Computer Engineering Systems, 2008, pp. xxiii–xxviii. November 2008Google Scholar
  25. 25.
    Voelter, M.: DSL Engineering - Designing, Implementing and Using Domain-Specific Languages. CreateSpace Independent Publishing Platform, Hamburg (2013)Google Scholar
  26. 26.
    Vytiniotis, D., Peyton Jones, S., Schrijvers, T., Sulzmann, M.: OutsideIn(X): modular type inference with local assumptions. J. Funct. Program. 21(4–5), 333–412 (2011)MathSciNetCrossRefMATHGoogle Scholar
  27. 27.
    Wadler, P.: Comprehending monads. In: Proceedings of the 1990 ACM Conference on LISP and Functional Programming, LFP 1990, NY, USA, pp. 61–78. ACM, New York (1990)Google Scholar
  28. 28.
    Yorgey, B.A.: Monoids: Theme and variations. In: Proceedings of the 2012 Haskell Symposium, Haskell 2012, NY, USA, pp. 105–116. ACM, New York (2012)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2016

Authors and Affiliations

  1. 1.Department of Information and Computing SciencesUtrecht UniversityUtrechtThe Netherlands

Personalised recommendations