Skip to main content

From Monads to Effects and Back

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 9585))

Abstract

The combination of monads and effects leads to a clean and easy to reason about programming paradigm. Monadic programming is easy to reason about, but can be cumbersome, as it requires explicit lifting and binding. In this paper, we combine monads and effects within a single programming paradigm: we use monads to define the semantics of effect types, and then, use the effects to program with those monads. We implemented an extension to the effect type system of Koka [15] with user defined effects. We use a type-directed translation to automatically lift effectful into monadic programs, by inserting bind - and unit operations.

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

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   34.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   44.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

Learn about institutional subscriptions

References

  1. Bauer, A., Pretnar, M.: An effect system for algebraic effects and handlers. Logical Methods Comput. Sci. 10(4), 1–29 (2014)

    Article  MathSciNet  Google Scholar 

  2. Bauer, A., Pretnar, M.: Programming with algebraic effects and handlers. J. Log. Algebr. Methods Program. 84(1), 108–123 (2015). doi:10.1016/j.jlamp.2014.02.001

    Article  MathSciNet  MATH  Google Scholar 

  3. Benton, N., Buchlovsky, P.: Semantics of an effect analysis for exceptions. In: TLDI (2007). doi:10.1145/1190315.1190320

  4. Benton, N., Kennedy, A., Beringer, L., Hofmann, M.: Relational semantics for effect-based program transformations with dynamic allocation. In: PPDP (2007). doi:10.1145/1273920.1273932

  5. Elliott, C., Hudak, P.: Functional reactive animation. In: ICFP (1997)

    Google Scholar 

  6. Filinski, A.: Representing monads. In: POPL (1994)

    Google Scholar 

  7. Filinski, A.: Controlling effects. Technical report (1996)

    Google Scholar 

  8. Filinski, A.: Monads in action. ACM Sigplan Not. 45, 483–494 (2010)

    Article  Google Scholar 

  9. Gifford, D.K., Lucassen, J.M.: Integrating functional and imperative programming. In: LFP (1986). doi:10.1145/319838.319848

  10. Girard, J.-Y.: The system F of variable types, fifteen years later. TCS 45, 159–192 (1986)

    Article  MathSciNet  MATH  Google Scholar 

  11. Gosling, J., Joy, B., Steele, G.: The java language specification (1996)

    Google Scholar 

  12. Hicks, M., Bierman, G., Guts, N., Leijen, D., Swamy, N.: Polymonadic programming. In: MSFP (2014)

    Google Scholar 

  13. Kiselyov, O., Shan, C.: Embedded probabilistic programming. In: Taha, W.M. (ed.) DSL 2009. LNCS, vol. 5658, pp. 360–384. Springer, Heidelberg (2009). doi:10.1007/978-3-642-03034-5_17

    Google Scholar 

  14. Leijen, D.: Koka: programming with row-polymorphic effect types. Technical report MSR-TR-2013-79, Microsoft Research (2013)

    Google Scholar 

  15. Leijen, D.: Koka: programming with row polymorphic effect types. In: MSFP (2014). doi:10.4204/EPTCS.153.8

    Google Scholar 

  16. Lucassen, J.M., Gifford, D.K.: Polymorphic effect systems. In: POPL (1988)

    Google Scholar 

  17. Moggi, E.: Notions of computation and monads. Inf. Comput. 93, 55–92 (1991)

    Article  MathSciNet  MATH  Google Scholar 

  18. Nielson, H.R., Nielson, F., Amtoft, T.: Polymorphic subtyping for effect analysis, the static semantics. In: LOMAPS (1997)

    Google Scholar 

  19. Pessaux, F., Leroy, X.: Type-based analysis of uncaught exceptions. In POPL (1999). doi:10.1145/292540.292565

  20. Plotkin, G.D., Matija, P., Handling algebraic effects. 9 (2013). doi:10.2168/LMCS-9(4:23)2013

  21. Pretnar, M.: Inferring algebraic effects. Logical Methods Comput. Sci. 10(3) (2014). doi: 10.2168/LMCS-10(3:21)2014

  22. Reynolds, J.C.: Towards a theory of type structure. In: Programming Symposium (1974)

    Google Scholar 

  23. Rompf, T., Maier, I., Odersky, M.: Implementing first-class polymorphic delimited continuations by a type-directed selective cps-transform. In: ICFP (2009)

    Google Scholar 

  24. Rytz, L., Odersky, M., Haller, P.: Lightweight polymorphic effects. In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 258–282. Springer, Heidelberg (2012). doi:10.1007/978-3-642-31057-7_13

    Google Scholar 

  25. Swamy, N., Guts, N., Leijen, D., Hicks, M.: Lightweight monadic programming in ML. In: ICFP (2011). doi:10.1145/2034773.2034778

  26. Talpin, J.-P., Jouvelot, P.: The type and effect discipline. Inf. Comput. (1994). doi: 10.1006/inco.1994.1046

    Google Scholar 

  27. Talpin, J.P.: Theoretical and practical aspects of type and effect inference. Ph.D. thesis, Ecole des Mines de Paris and University Paris VI, Paris, France (1993)

    Google Scholar 

  28. Vazou, N., Leijen, D.: From monads to effects and back - technical report. Technical report, July 2015. http://goto.ucsd.edu/~nvazou/padl16/techrep.pdf

  29. Wadler, P.: The essence of functional programming. In: POPL (1992)

    Google Scholar 

  30. Wadler, P., Thiemann, P.: The marriage of effects and monads. In: TOLC (2003). doi: 10.1145/601775.601776

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Niki Vazou .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer International Publishing Switzerland

About this paper

Cite this paper

Vazou, N., Leijen, D. (2016). From Monads to Effects and Back. In: Gavanelli, M., Reppy, J. (eds) Practical Aspects of Declarative Languages. PADL 2016. Lecture Notes in Computer Science(), vol 9585. Springer, Cham. https://doi.org/10.1007/978-3-319-28228-2_11

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-28228-2_11

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-28227-5

  • Online ISBN: 978-3-319-28228-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics