Skip to main content

Handling Local State with Global State

  • Conference paper
  • First Online:
Book cover Mathematics of Program Construction (MPC 2019)

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

Included in the following conference series:

Abstract

Equational reasoning is one of the most important tools of functional programming. To facilitate its application to monadic programs, Gibbons and Hinze have proposed a simple axiomatic approach using laws that characterise the computational effects without exposing their implementation details. At the same time Plotkin and Pretnar have proposed algebraic effects and handlers, a mechanism of layered abstractions by which effects can be implemented in terms of other effects.

This paper performs a case study that connects these two strands of research. We consider two ways in which the nondeterminism and state effects can interact: the high-level semantics where every nondeterministic branch has a local copy of the state, and the low-level semantics where a single sequentially threaded state is global to all branches.

We give a monadic account of the folklore technique of handling local state in terms of global state, provide a novel axiomatic characterisation of global state and prove that the handler satisfies Gibbons and Hinze’s local state axioms by means of a novel combination of free monads and contextual equivalence. We also provide a model for global state that is necessarily non-monadic.

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.

    The proof can be found at https://github.com/KoenP/LocalAsGlobal.

  2. 2.

    Gibbons and Hinze [4] were mistaken in their claim that the type \( s \rightarrow [( a , s )]\) constitutes a model of their backtrackable state laws; it is not a model because its does not commute with itself. One could consider a relaxed semantics that admits \( s \rightarrow [( a , s )]\), but that is not the focus of this paper.

References

  1. Aït-Kaci, H.: Warren’s Abstract Machine: A Tutorial Reconstruction (1991)

    Google Scholar 

  2. Bauer, A., Pretnar, M.: An effect system for algebraic effects and handlers. Logical Methods Comput. Sci. 10(4) (2014). https://doi.org/10.2168/LMCS-10(4:9)2014

  3. Gale, Y.: ListT done right alternative (2007). https://wiki.haskell.org/ListT_done_right_alternative

  4. Gibbons, J., Hinze, R.: Just do it: simple monadic equational reasoning. In: Danvy, O. (ed.) International Conference on Functional Programming, pp. 2–14. ACM Press (2011)

    Google Scholar 

  5. Gill, A., Kmett, E.: The monad transformer library (2014). https://hackage.haskell.org/package/mtl

  6. Hinze, R.: Prolog’s control constructs in a functional setting - axioms and implementation. Int. J. Found. Comput. Sci. 12(2), 125–170 (2001). https://doi.org/10.1142/S0129054101000436

    Article  MATH  Google Scholar 

  7. Hutton, G., Fulger, D.: Reasoning about effects: seeing the wood through the trees. In: Symposium on Trends in Functional Programming (2007)

    Google Scholar 

  8. Kiselyov, O.: Laws of monadplus (2015). http://okmij.org/ftp/Computation/monads.html#monadplus

  9. Kiselyov, O., Ishii, H.: Freer monads, more extensible effects. In: Reppy, J.H. (ed.) Symposium on Haskell, pp. 94–105. ACM Press (2015)

    Google Scholar 

  10. Lukšič, V., Pretnar, M.: Local algebraic effect theories (2019, submitted)

    Google Scholar 

  11. Moggi, E.: Computational lambda-calculus and monads. In: Parikh, R. (ed.) Logic in Computer Science, pp. 14–23. IEEE Computer Society Press (1989)

    Google Scholar 

  12. Plotkin, G., Pretnar, M.: Handlers of algebraic effects. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 80–94. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-00590-9_7

    Chapter  Google Scholar 

  13. Volkov, N.: The list-t package (2014). http://hackage.haskell.org/package/list-t

  14. Wadler, P.: Monads for functional programming. In: Broy, M. (ed.) Program Design Calculi: Marktoberdorf Summer School, pp. 233–264. Springer, Heidelberg (1992). https://doi.org/10.1007/978-3-662-02880-3_8

    Chapter  Google Scholar 

  15. Wu, N., Schrijvers, T., Hinze, R.: Effect handlers in scope. In: Voigtländer, J. (ed.) Symposium on Haskell, pp. 1–12. ACM Press (2012)

    Google Scholar 

Download references

Acknowledgements

We would like to thank Matija Pretnar, the members of IFIP WG 2.1, the participants of Shonan meeting 146 and the MPC reviewers for their insightful comments. We would also like to thank the Flemish Fund for Scientific Research (FWO) for their financial support.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Koen Pauwels .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Pauwels, K., Schrijvers, T., Mu, SC. (2019). Handling Local State with Global State. In: Hutton, G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science(), vol 11825. Springer, Cham. https://doi.org/10.1007/978-3-030-33636-3_2

Download citation

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

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-33635-6

  • Online ISBN: 978-3-030-33636-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics