Skip to main content

Towards Efficient Adjustment of Effect Rows

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

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

Included in the following conference series:

  • 166 Accesses

Abstract

Koka is a functional programming language with native support for algebraic effects and handlers. To implement effect handler operations efficiently, Koka employs a semantics where the handlers in scope are passed down to each function as an evidence vector. At runtime, these evidence vectors are adjusted using the open constructs to match the evidence for a particular function. All these adjustments can cause significant runtime overhead. In this paper, we present a novel transformation on the Koka core calculus that we call open floating. This transformation aims to float up open constructs and combine them in order to minimize the adjustments needed at runtime. Open floating improves performance by 2.5\(\times \) in an experiment. Furthermore, we formalize an aspect of row-based effect typing, including the closed prefix relation on effect rows, which clarifies the constraint on open floating.

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 49.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.

    Kind annotations directly relate their types to the specific symbols associated with them, such as \({\mu {}}\) and \({{ c _ l }}\). This allows us to use these symbols just as aliases.

  2. 2.

    In the Koka-related literature [9, 19, 20], an effect row is called closed when it ends with \({\langle \rangle {}}\), and open when its tail ends with a type variable. We adopt the naming convention of the above literature.

References

  1. Brachthäuser, J.I., Schuster, P., Ostermann, K.: Lightweight effect polymorphism for handlers. Technical report. University of Tübingen, Germany, Effekt (2020)

    Google Scholar 

  2. Dolan, S., White, L., Sivaramakrishnan, K.C., Yallop, J., Madhavapeddy, A.: Effective Concurrency through algebraic effects. In: OCaml Workshop, vol. 13 (2015)

    Google Scholar 

  3. Felleisen, M.: The theory and practice of first-class prompts. In: Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 180–190. POPL ’88. Association for Computing Machinery, New York, NY, USA (1988). 10.1145/73560.73576

  4. Gaster, B.R., Jones, M.P.: A Polymorphic Type System for Extensible Records and Variants. NOTTCS-TR-96-3. University of Nottingham (1996)

    Google Scholar 

  5. Jones, M.P.: A theory of qualified types. In: Krieg-Brückner, B. (ed.) ESOP 1992. LNCS, vol. 582, pp. 287–306. Springer, Heidelberg (1992). https://doi.org/10.1007/3-540-55253-7_17

    Chapter  Google Scholar 

  6. Jones, M.P.: Simplifying and improving qualified types. In: Proceedings of the 7th International Conference on Functional Programming Languages and Computer Architecture, pp. 160–169. FPCA ’95. La Jolla, California, USA (1995). 10.1145/224164.224198

  7. Leijen, D.: Koka: programming with row polymorphic effect types. In: MSFP’14, 5th Workshop on Mathematically Structured Functional Programming (2014). 10.4204/EPTCS.153.8

  8. Leijen, D.: Structured asynchrony with algebraic effects. In: Proceedings of the 2nd ACM SIGPLAN International Workshop on Type-Driven Development, TyDe 2017. Oxford, UK, pp. 16–29 (2017). 10.1145/3122975.3122977

  9. Leijen, D.: Type directed compilation of row-typed algebraic effects. In: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, pp. 486–499 (2017)

    Google Scholar 

  10. Leijen, D.: Type directed compilation of row-typed algebraic effects. In: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL’17), Paris, France, pp. 486–499 (2017). 10.1145/3009837.3009872

  11. Leijen, D.: Koka repository (2019). https://github.com/koka-lang/koka

  12. Morris, J.G., McKinna, J.: Abstracting extensible data types: or, rows by any other name. In: Proceedings of the ACM on Programming Languages, vol. 3 (POPL). ACM New York, NY, USA, pp. 1–28 (2019)

    Google Scholar 

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

    Google Scholar 

  14. Plotkin, G.D., Pretnar, M.: Handling algebraic effects. In: Logical Methods in Computer Science, vol. 9, no. 4 (2013). 10.2168/LMCS-9(4:23)2013

  15. Pretnar, M., Saleh, A.H., Faes, A., Schrijvers, T.: Efficient compilation of algebraic effects and handlers. CW Reports. Department of Computer Science, KU Leuven, Leuven, Belgium (2017). https://lirias.kuleuven.be/retrieve/472230

  16. Saleh, A.H., Karachalias, G., Pretnar, M., Schrijvers, T.: Explicit effect subtyping. In: Ahmed, A. (ed.) ESOP 2018. LNCS, vol. 10801, pp. 327–354. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-89884-1_12

    Chapter  Google Scholar 

  17. Shields, M., Meijer, E.: Type-indexed rows. In: Proceedings of the 28th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL’01, London, United Kingdom, pp. 261–275 (2001) 10.1145/360204.360230

  18. Wadler, P., Blott, S.: How to make ad-hoc polymorphism less ad hoc. In: Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’89. ACM, Austin, Texas, USA, pp. 60–76 (1989). 10.1145/75277.75283

  19. Xie, N., Brachthäuser, J.I., Hillerström, D., Schuster, P., Leijen, D.: Effect handlers, evidently. In: Proceedings of the ACM on Programming Languages, vol. 4 (ICFP). ACM New York, NY, USA, pp. 1–29 (2020)

    Google Scholar 

  20. Xie, N., Leijen, D.: Generalized evidence passing for effect handlers: efficient compilation of effect handlers to C. In: Proceedings of the ACM Programming Languages, vol. 5 (ICFP). Association for Computing Machinery, New York, NY, USA (2021). 10.1145/3473576

Download references

Acknowledgement

We acknowledge the reviewers’ efforts put into evaluation of our paper. We also appreciate the FLOPS 2022 reviewers’ feedback on an earlier version of the paper. Lastly, we thank members of Masuhara laboratory. This work was supported in part by JSPS KAKENHI under Grant No. JP19K24339.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Naoya Furudono .

Editor information

Editors and Affiliations

Appendix

Appendix

We present the well-formedness relation \({\!\vdash _{\!\textsf {wf}}}\) and definitional equality of types \({\!\vdash _{\!\textsf {eq}}}\) in Fig. 9. The type rules (Fig. 4) use these relations.

Fig. 9.
figure 9

Well-formedness and definitional equality of types of system

Rights and permissions

Reprints and permissions

Copyright information

© 2022 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Furudono, N., Cong, Y., Masuhara, H., Leijen, D. (2022). Towards Efficient Adjustment of Effect Rows. In: Swierstra, W., Wu, N. (eds) Trends in Functional Programming. TFP 2022. Lecture Notes in Computer Science, vol 13401. Springer, Cham. https://doi.org/10.1007/978-3-031-21314-4_9

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-21314-4_9

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-21313-7

  • Online ISBN: 978-3-031-21314-4

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics