Skip to main content

BinderAnn: Automated Reification of Source Annotations for Monadic EDSLs

  • Conference paper
  • First Online:
Trends in Functional Programming (TFP 2020)

Abstract

Embedded Domain-Specific Languages (EDSLs) are an alternative to quickly implement specialized languages without the need to write compilers or interpreters from scratch. In this territory, Haskell is a prime choice as the host language. EDSLs in Haskell, however, are often incapable of reifying useful static information from the source code, namely variable binding names and source locations. Not having access to variable names directly affects EDSLs designed to generate low-level code, where the variables names in the generated code do not match those found in the source code—thus broadening the semantic gap among source and target code. Similarly, many existing EDSLs produce poor error messages due to the lack of knowledge of source locations where errors are generated.

In this work, we propose a simple technique for enhancing monadic EDSLs expressed using \(\mathbf {do}\) notation. This technique employs source-to-source plugins, a relatively new feature of GHC, to annotate every \(\mathbf {do}\) statement of our EDSLs with relevant information extracted from the source code at compile time. We show how these annotations can be incorporated into EDSL designs either directly inside values or as monadic effects. We provide BinderAnn, a GHC source plugin implementing our ideas, and evaluate it by enhancing existing real-world EDSLs with relatively minor modification efforts to contemplate the source-level static information related to variables names and source locations.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    DOT is a graph description language used by many open source applications.

  2. 2.

    Available at https://github.com/OctopiChalmers/BinderAnn.

  3. 3.

    Available at http://github.com/OctopiChalmers/BinderAnn-examples.

  4. 4.

    Available at http://github.com/OctopiChalmers/PropProver.

References

  1. Algehed, M., Jansson, P., Einarsdóttir, S.H., Gerdes, A.: Saint: an API-generic type-safe interpreter. In: Pałka, M., Myreen, M. (eds.) TFP 2018. LNCS, vol. 11457, pp. 94–113. Springer, Cham (2019). https://doi.org/10.1007/978-3-030-18506-0_5

    Chapter  Google Scholar 

  2. Axelsson, E.: Compilation as a typed EDSL-to-EDSL transformation. arXiv preprint arXiv:1603.08865 (2016)

  3. Axelsson, E., et al.: Feldspar: a domain specific language for digital signal processing algorithms. In: Eighth ACM/IEEE International Conference on Formal Methods and Models for Codesign (MEMOCODE 2010), pp. 169–178. IEEE (2010)

    Google Scholar 

  4. Barras, B., et al.: The Coq proof assistant reference manual: version 6.1 (1997)

    Google Scholar 

  5. Dévai, G., Leskó, D., Tejfel, M.: The EDSL’s struggle for their sources. In: Zsók, V., Horváth, Z., Csató, L. (eds.) CEFP 2013. LNCS, vol. 8606, pp. 300–335. Springer, Cham (2015). https://doi.org/10.1007/978-3-319-15940-9_7

    Chapter  Google Scholar 

  6. Eisenberg, R.A., Vytiniotis, D., Peyton Jones, S., Weirich, S.: Closed type families with overlapping equations. ACM SIGPLAN Not. 49(1), 671–683 (2014)

    Article  Google Scholar 

  7. Ekblad, A.: shellmate: Simple interface for shell scripting in Haskell (2014). https://hackage.haskell.org/package/shellmate

  8. Elliott, T., et al.: Guilt free ivory. In: ACM SIGPLAN Notices, no. 12. ACM (2015)

    Google Scholar 

  9. Erkok, L.: SBV: SMT based verification: symbolic Haskell theorem prover using SMT solving (2010). https://hackage.haskell.org/package/sbv

  10. Gill, A.: dotgen: A simple interface for building.dot graph files (2008). https://hackage.haskell.org/package/dotgen

  11. Giorgidze, G., Grust, T., Schreiber, T., Weijers, J.: Haskell boards the ferry. In: Hage, J., Morazán, M.T. (eds.) IFL 2010. LNCS, vol. 6647, pp. 1–18. Springer, Heidelberg (2011). https://doi.org/10.1007/978-3-642-24276-2_1

    Chapter  Google Scholar 

  12. Giorgidze, G., Nilsson, H.: Embedding a functional hybrid modelling language in Haskell. In: Scholz, S.-B., Chitil, O. (eds.) IFL 2008. LNCS, vol. 5836, pp. 138–155. Springer, Heidelberg (2011). https://doi.org/10.1007/978-3-642-24452-0_8

    Chapter  Google Scholar 

  13. Hall, C.V., Hammond, K., Peyton Jones, S.L., Wadler, P.L.: Type classes in Haskell. ACM Trans. Program. Lang. Syst. (TOPLAS) 18(2), 109–138 (1996)

    Article  Google Scholar 

  14. Hudak, P., et al.: Building domain-specific embedded languages. ACM Comput. Surv. 28(4es), 196 (1996)

    Article  Google Scholar 

  15. Jones, S.L.P., Santos, A.M.: A transformation-based optimiser for Haskell. Sci. Comput. Program. 32(1–3), 3–47 (1998)

    Article  Google Scholar 

  16. Jones, S.P., Jones, M., Meijer, E.: Type classes: an exploration of the design space. In: Haskell Workshop, pp. 1–16 (1997)

    Google Scholar 

  17. Launchbury, J.: Lazy imperative programming. In: Workshop on State in Programming Languages, Copenhagen, Denmark. ACM (1993)

    Google Scholar 

  18. Mainland, G.: Why it’s nice to be quoted: quasiquoting for Haskell. In: Proceedings of the ACM SIGPLAN Workshop on Haskell Workshop, pp. 73–82. ACM (2007)

    Google Scholar 

  19. Mainland, G., Morrisett, G.: Nikola: embedding compiled GPU functions in Haskell. ACM SIGPLAN Not. 45, 67–78 (2010)

    Article  Google Scholar 

  20. Marlow, S., Jones, S.P., et al.: The Glasgow Haskell compiler (2004)

    Google Scholar 

  21. Pickering, M., Wu, N., Németh, B.: Working with source plugins. In: Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell. ACM (2019)

    Google Scholar 

  22. Pike, L., Goodloe, A., Morisset, R., Niller, S.: Copilot: a hard real-time runtime monitor. In: Barringer, H., et al. (eds.) RV 2010. LNCS, vol. 6418, pp. 345–359. Springer, Heidelberg (2010). https://doi.org/10.1007/978-3-642-16612-9_26

    Chapter  Google Scholar 

  23. Sheard, T., Jones, S.L.P.: Template meta-programming for Haskell. SIGPLAN Not. 37(12), 60–75 (2002)

    Article  Google Scholar 

  24. Snoyman, M.: Developing Web Applications with Haskell and Yesod. O’Reilly Media Inc., Sebastopol (2012)

    Google Scholar 

  25. Wadler, P.: Monads for functional programming. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 24–52. Springer, Heidelberg (1995). https://doi.org/10.1007/3-540-59451-5_2

    Chapter  Google Scholar 

Download references

Acknowledgment

We want to thank Koen Claessen for the useful feedback given throughout the development of this work. This work was funded by the Swedish Foundation for Strategic Research (SSF) under the project Octopi (Ref. RIT17-0023) and WebSec (Ref. RIT17-0011) as well as the Swedish research agency Vetenskapsrådet.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Agustín Mista .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Mista, A., Russo, A. (2020). BinderAnn: Automated Reification of Source Annotations for Monadic EDSLs. In: Byrski, A., Hughes, J. (eds) Trends in Functional Programming. TFP 2020. Lecture Notes in Computer Science(), vol 12222. Springer, Cham. https://doi.org/10.1007/978-3-030-57761-2_2

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-57761-2_2

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-57760-5

  • Online ISBN: 978-3-030-57761-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics