Abstract
Domain-specific languages (DSLs) permeate current programming practices. An important kind of DSLs includes those developed and integrated within a host language, which we call embedded or internal DSLs. Unfortunately, embedded DSLs usually fall short on domain-specific error diagnosis, that is, they do not give control to DSL authors over how errors are reported to the programmer. As a consequence, implementation details of the DSL leak through in error messages, and programmers need to understand the internals of the DSL implementation to fix their code in a productive way. This paper addresses the challenge of building a compiler with integrated support for domain-specific error diagnosis. We assume that the type system is described using a constraint-based approach, and constraint solving is specified using rewrite rules. Domain information can then be injected at constraint gathering time via type rules, during constraint solving via specialized rules and axioms, and finally at blaming and reparation time via transformations. Furthermore, we define error contexts as a way to control the order in which solving and blaming proceeds. We engineer domain-specific error diagnosis in such a way that the compiler can also reuse the techniques for improving general error diagnosis.
References
[1] Voelter M., DSL Engineering - Designing, Implementing and Using Domain-Specific Languages, 2013Search in Google Scholar
[2] Hudak P., Building domain-specific embedded languages, ACM Computing Surveys (CSUR) - Special issue: position statements on strategic directions in computing research, 1996, 28(4es), Article No. 19610.1145/242224.242477Search in Google Scholar
[3] Marlow S., Haskell 2010 Language Report, 2010, https://www. haskell.org/onlinereport/haskell2010/Search in Google Scholar
[4] Hage J., Domain specific type error diagnosis (DOMSTED), Technical Report UU-CS-2014-019, Department of Information and Computing Sciences, Utrecht University, 2014Search in Google Scholar
[5] 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 ’82), ACM, 1982, 207-21210.1145/582153.582176Search in Google Scholar
[6] Lee O., Yi K., Proofs about a folklore let-polymorphic type inference algorithm, ACM Transactions on Programming Languages and Systems (TOPLAS), 1998, 20(4), 707-72310.1145/291891.291892Search in Google Scholar
[7] Vytiniotis D., Peyton Jones S., Schrijvers T., Sulzmann M., OutsideIn(X): Modular type inference with local Assumptions, Journal of Functional Programming, 2011, 21(4-5), 333-41210.1017/S0956796811000098Search in Google Scholar
[8] Swift Team, Type checker design and implementation, 2016Search in Google Scholar
[9] Elm Team, Source code for Elm type checker, file Type/Solve.hs, 2018Search in Google Scholar
[10] Sulzmann M., Wazny J., Stuckey P. J., A Framework for ExtendedSearch in Google Scholar
Algebraic Data Types, In: Hagiya M., Wadler P. (Eds.), Functional and Logic Programming, FLOPS 2006, Lecture Notes in Computer Science, vol 3945, Springer, Berlin, Heidelberg 2006, 47-64Search in Google Scholar
[11] Pottier F., Rémy D., The essence of ML type inference, In: Pierce B. C. (Ed.), Advanced Topics in Types and Programming Languages, MIT Press, 2005, 10, 389-48910.7551/mitpress/1104.003.0016Search in Google Scholar
[12] McAdam B. J., On the unification of substitutions in type inference, In: Hammond K., Davie T., Clack C. (Eds.), Implementation of Functional Languages, Lecture Notes in Computer Science, 1999, 1595, 137-15210.1007/3-540-48515-5_9Search in Google Scholar
[13] 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 ’03), ACM, 2003, 3-1310.1145/944705.944707Search in Google Scholar
[14] Heeren B. J., Top Quality Type Error Messages. Ph.D. thesis, Universiteit Utrecht, The Netherlands, September 2005Search in Google Scholar
[15] Sulzmann M., Duck G. J., Peyton Jones S., Stuckey P. J., Understanding Functional Dependencies via Constraint Handling Rules, Journal of Functional Programming, 2007, 17(1), 83-12910.1017/S0956796806006137Search in Google Scholar
[16] Heeren B., Leijen D., van IJzendoorn A., Helium, for learning Haskell, In: Proceedings of the 2003 ACM SIGPLAN workshop on Haskell (Haskell ’03), ACM, 2003, 62-7110.1145/871895.871902Search in Google Scholar
[17] Hage J., Heeren B., Heuristics for type error discovery and recovery, In: Horváth Z., Zsók V., Butterfield A. (Eds.), Implementation and Application of Functional Languages, IFL 2006, Lecture Notes in Computer Science, Springer, Berlin, Heidelberg, 2006, 4449, 199-21610.1007/978-3-540-74130-5_12Search in Google Scholar
[18] Stuckey P. J., Sulzmann M., Wazny J., Type processing by constraint reasoning, In: Kobayashi N. (Ed.), Programming Languages and Systems, Lecture Notes in Computer Science, 2006, 4279, 1-2510.1007/11924661_1Search in Google Scholar
[19] Zhang D., Myers A. C., Toward general diagnosis of static errors, In: Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’14), ACM, New York, NY, USA, 2014, 569-58110.1145/2535838.2535870Search in Google Scholar
[20] Pavlinovic Z., King T., Wies T., Practical SMT-based type error localization, In: Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015), ACM, 2015, 412-42310.1145/2784731.2784765Search in Google Scholar
[21] Loncaric C., Chandra S., Schlesinger C., Sridharan M., A practical framework for type inference error Explanation, In: Proceedings of the 2016 ACM SIGPLAN International Conference on Object- Oriented Programming, Systems, Languages, and Applications (OOPSLA 2016), 2016, 781-79910.1145/2983990.2983994Search in Google Scholar
[22] McAdam B., How to repair type errors automatically, In: Trends in Functional Programming, Intellect Books, Exeter, UK, 2002, 87-98Search in Google Scholar
[23] Diatchki I., Custom type errors, 2015, Available at https://ghc. haskell.org/trac/ghc/wiki/Proposal/CustomTypeErrorsSearch in Google Scholar
[24] Scala Team, Docs for scala.annotation.implicitNotFound, 2015, Retrieved from https://www.scala-lang.org/api/2.12.7/scala/ annotation/implicitNotFound.htmlSearch in Google Scholar
[25] Stuckey P. J., Sulzmann M., A theory of overloading, In: Proceedings of the seventh ACM SIGPLAN international conference on Functional programming (ICFP ’02), ACM, 2002, 167-17810.1145/581478.581495Search in Google Scholar
[26] Gundry A., A typechecker plugin for units of measure: domain-specific constraint solving in GHC Haskell, In: Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell (Haskell 2015), ACM, 2015, 11-2210.1145/2804302.2804305Search in Google Scholar
[27] Wazny J., Type inference and type error diagnosis for Hindley/Milner with extensions, Ph.D. thesis, University of Melbourne, Australia, 2006Search in Google Scholar
[28] Serrano A., Hage J., Context-dependent type error diagnosis for functional languages, Technical Report UU-CS-2016-011, Department of Information and Computing Sciences, Utrecht University, 2016Search in Google Scholar
[29] Serrano A., Hage J., Type error diagnosis for embedded DSLs by two-stage specialized type rules, In: Proceedings of the 25th European Symposium on Programming Languages and Systems (ESOP 2016), Springer-Verlag New York, 2016, 9632, 672-69810.1007/978-3-662-49498-1_26Search in Google Scholar
[30] Serrano A., Hage J., From attribute grammars to constraint handling rules, Technical Report UU-CS- 2016-010, Department of Information and Computing Sciences, Utrecht University, 2016Search in Google Scholar
[31] Lorenzen F., Erdweg S., Sound type-dependent syntactic language extension, In: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2016), ACM, 2016, 204-21610.1145/2837614.2837644Search in Google Scholar
[32] Serrano A., Hage J., Lightweight Soundness for Towers of Language Extensions, In: Proceedings of the 2017 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM 2017), ACM, 2017, 23-3410.1145/3018882.3018884Search in Google Scholar
[33] De Koninck L., Schrijvers T., Demoen B., A flexible search framework for CHR, In: Schrijvers T., Frühwirth T. (Eds.), Constraint Handling Rules, Lecture Notes in Computer Science, Springer, Berlin, Heidelberg, 2008, 5388, 16-4710.1007/978-3-540-92243-8_2Search in Google Scholar
[34] Pfenning F., Elliott C., Higher-order abstract syntax, In: Proceedings of the ACM SIGPLAN 1988 conference on Programming language design and implementation (PLDI ’88), ACM, 1988, 199-20810.1145/53990.54010Search in Google Scholar
[35] Peyton Jones S., Vytiniotis D., Weirich S., Shields M., Practical type inference for arbitrary-rank types, Journal of Functional Programming, 2007, 17(1), 1-8210.1017/S0956796806006034Search in Google Scholar
[36] Serrano A., Hage J., Vytiniotis D., Peyton Jones S., Guarded impredicative polymorphism, In: Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2018), ACM, 2018, 783-79610.1145/3192366.3192389Search in Google Scholar
[37] Chakravarty M. M. T., Keller G., Peyton Jones S., Associated type synonyms, In: Proceedings of the tenth ACM SIGPLAN international conference on Functional programming (ICFP ’05), ACM, 2005, 241-25310.1145/1086365.1086397Search in Google Scholar
[38] Hage J., Heeren B., Strategies for Solving Constraints in Type and Effect Systems, Electronic Notes in Theoretical Computer Science, 2009, 236, 163-18310.1016/j.entcs.2009.03.021Search in Google Scholar
[39] Heeren B., Hage J., Type class directives, In: Hermenegildo M. V., Cabeza D. (Eds.), Practical Aspects of Declarative Languages, PADL 2005, Lecture Notes in Computer Science, Springer, Berlin, Heidelberg, 2005, 3350, 253-26710.1007/978-3-540-30557-6_19Search in Google Scholar
[40] Morris J. G., Jones M. P., Instance chains: type class programming without overlapping instances, In: Proceeding of the 15th ACM SIGPLAN international conference on Functional programming (ICFP 2010), ACM, 2010, 45, 375-38610.1145/1932681.1863596Search in Google Scholar
[41] Kiselyov O., Lämmel R., Schupke K., Strongly typed heterogeneous collections, In: Proceedings of the 2004 ACM SIGPLAN workshop on Haskell (Haskell ’04), ACM, 2004, 96-10710.1145/1017472.1017488Search in Google Scholar
[42] Christiansen D. R., Reflect on Your Mistakes! Lightweight Domain- Specific Error Messages, Presented at TFP 2014, 2014, http:// davidchristiansen.dk/drafts/error-reflection-submission.pdfSearch in Google Scholar
[43] Plociniczak H., Miller H., Odersky M., Improving Human-Compiler Interaction Through Customizable Type Feedback, 2014, https: //infoscience.epfl.ch/record/197948/files/splash2014.pdfSearch in Google Scholar
© 2019 Alejandro Serrano and Jurriaan Hage, published by De Gruyter Open
This work is licensed under the Creative Commons Attribution 4.0 Public License.