Skip to main content

Effect Systems Revisited—Control-Flow Algebra and Semantics

  • Chapter
  • First Online:
Semantics, Logics, and Calculi

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 9560))

Abstract

Effect systems were originally conceived as an inference-based program analysis to capture program behaviour—as a set of (representations of) effects. Two orthogonal developments have since happened. First, motivated by static analysis, effects were generalised to values in an algebra, to better model control flow (e.g. for may/must analyses and concurrency). Second, motivated by semantic questions, the syntactic notion of set- (or semilattice-) based effect system was linked to the semantic notion of monads and more recently to graded monads which give a more precise semantic account of effects.

We give a lightweight tutorial explanation of the concepts involved in these two threads and then unify them via the notion of an effect-directed semantics for a control-flow algebra of effects. For the case of effectful programming with sequencing, alternation and parallelism—illustrated with music—we identify a form of graded joinads as the appropriate structure for unifying effect analysis and semantics.

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.

    To slightly shorten the example, the melody of the last phrase repeats that of the first. Musicians are invited to use the correct notes: F2;F2;E2;C2;D2;C2.

  2. 2.

    This easily maps to the \(\lambda \)-calculus-with-constants formulation used in later sections by replacing the statement with and a tail-recursive call, and by treating \(e;e'\) as shorthand for for some fresh variable x.

  3. 3.

    Mathematically, \(\mathsf {T}\) is an endofunctor, but languages such as Haskell (and the Monad language in this section) expose monads syntactically as parametric type constructors M; thus side-effecting functions have analogous types \(\tau \rightarrow M \tau '\). We try not to labour either this distinction or that between types (often written AB instead of \(\tau ,\tau '\) above) and the categorical objects AB which model them (more formally \({\llbracket {\tau }\rrbracket },{\llbracket {\tau '}\rrbracket }\)).

  4. 4.

    We use \([-]\) for translation into another language and reserve \(\llbracket - \rrbracket \) for semantic interpretation (denotation) as in the next section.

  5. 5.

    Katsumata uses ‘pre-ordered’ but we simply consider \((\sqsubseteq )\cap (\sqsubseteq ^{-1})\) equivalence classes.

  6. 6.

    Section 3 addresses the subtlety here that is reflected with operation \(+\) in the music effect while Katsumata’s graded monads use a relation \(\sqsubseteq \).

  7. 7.

    Categorically, a natural transformation, derived from coproducts with \(\mathbb {B} = 1 + 1\).

  8. 8.

    Laxity means that the homomorphic map \(\mathsf {T}: \mathcal {F} \rightarrow [\mathcal {C},\mathcal {C}]\) from effects to type-constructors (endofunctors) on \(\mathcal {C}\) has functions witnessing the mapping between structure on \(\mathcal {F}\) and on \([\mathcal {C},\mathcal {C}]\), e.g., \( \mathsf {merge}^{F,G}_{A,B} : \mathsf {T}_F A \times \mathsf {T}_G B \rightarrow \mathsf {T}_{F \& G} (A \times B)\), rather than equalities, e.g., \( \mathsf {T}_F A \times \mathsf {T}_G B = \mathsf {T}_{F \& G} (A \times B)\).

References

  1. Aaron, S., Orchard, D., Blackwell, A.F.: Temporal semantics for a live coding language. In: Proceeding 2nd ACM SIGPLAN International Workshop on Functional Art, Music, Modelling and Design, pp. 37–47. ACM (2014)

    Google Scholar 

  2. Amtoft, T., Nielson, F., Nielson, H.: Type and Effect Systems Behaviours for Concurrency. Imperial College Press (1999)

    Google Scholar 

  3. Atkey, R.: Parameterised notions of computation. Cambridge University Press. In: Proceedings of MSFP (2006)

    Google Scholar 

  4. Benton, N., Kennedy, A., Hofmann, M.O., Beringer, L.: Reading, writing and relations. In: Kobayashi, N. (ed.) APLAS 2006. LNCS, vol. 4279, pp. 114–130. Springer, Heidelberg (2006)

    Chapter  Google Scholar 

  5. Brunel, A., Gaboardi, M., Mazza, D., Zdancewic, S.: A core quantitative coeffect calculus. In: Shao, Z. (ed.) ESOP 2014 (ETAPS). LNCS, vol. 8410, pp. 351–370. Springer, Heidelberg (2014)

    Chapter  Google Scholar 

  6. Cousot, P., Cousot, R.: Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In: Proceedings of POPL, pp. 238–252. ACM (1977)

    Google Scholar 

  7. Flanagan, C., Qadeer, S.: A type and effect system for atomicity. In: Proceedings of PLDI 2003. ACM (2003)

    Google Scholar 

  8. Ghica, D.R., Smith, A.I.: Bounded linear types in a resource semiring. In: Shao, Z. (ed.) ESOP 2014 (ETAPS). LNCS, vol. 8410, pp. 331–350. Springer, Heidelberg (2014)

    Chapter  Google Scholar 

  9. Gifford, D.K., Lucassen, J.M.: Integrating functional and imperative programming. In: Proceedings of Conference on LISP and Functional Programming, LFP 1986 (1986)

    Google Scholar 

  10. Goncharov, S., Schröder, L., Mossakowski, T.: Kleene monads: handling iteration in a framework of generic effects. In: Kurz, A., Lenisa, M., Tarlecki, A. (eds.) CALCO 2009. LNCS, vol. 5728, pp. 18–33. Springer, Heidelberg (2009)

    Chapter  Google Scholar 

  11. Honda, K., Vasconcelos, V.T., Kubo, M.: Language primitives and type discipline for structured communication-based programming. In: Hankin, C. (ed.) ESOP 1998. LNCS, vol. 1381, pp. 122–138. Springer, Heidelberg (1998)

    Chapter  Google Scholar 

  12. Jouvelot, P., Gifford, D.K.: Communication Effects for Message-Based Concurrency. Technical report, Massachusetts Institute of Technology (1989)

    Google Scholar 

  13. Jouvelot, P., Gifford, D.K.: Reasoning about continuations with control effects. In: Proceedings of PLDI 1989. ACM (1989)

    Google Scholar 

  14. Kammar, O.: Algebraic theory of type-and-effect systems, Ph.D. dissertation. The University of Edinburgh (2014)

    Google Scholar 

  15. Kammar, O., Plotkin, G.D.: Algebraic foundations for effect-dependent optimisations. In: Proceedings of POPL 2012, pp. 349–360. ACM (2012)

    Google Scholar 

  16. Katsumata, S.: Parametric effect monads and semantics of effect systems. In: Proceedings of POPL 2014, pp. 633–645. ACM (2014)

    Google Scholar 

  17. Kiselyov, O., Shan, C.C., Friedman, D.P., Sabry, A.: Backtracking, interleaving, and terminating monad transformers (functional pearl). In: Proceedings of ICFP 2005, pp. 192–203. ACM (2005)

    Google Scholar 

  18. Lucassen, J.M., Gifford, D.K.: Polymorphic effect systems. In: Proceedings of the 15th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pp. 47–57. ACM (1988)

    Google Scholar 

  19. Madhavapeddy, A., Mortier, R., Rotsos, C., Scott, D., Singh, B., Gazagnaire, T., Smith, S., Hand, S., Crowcroft, J.: Unikernels: library operating systems for the cloud. SIGPLAN Not. 48(4), 461–472 (2013)

    Article  Google Scholar 

  20. Mellies, P.A.: Parametric monads and enriched adjunctions (2012) http://www.pps.univ-paris-diderot.fr/mellies/tensorial-logic.html

  21. Milius, S., Pattinson, D., Schröder, L.: Generic trace semantics and graded monads. In: Proceedings of 6th International Conference in Algebra and Coalgebra in Computer Science (2015)

    Google Scholar 

  22. Milner, R.: Communication and Concurrency, vol. 84. Prentice Hall, New York (1989)

    MATH  Google Scholar 

  23. Moggi, E.: Computational lambda-calculus and monads. In: Fourth Annual Symposium on Logic in Computer Science, pp. 14–23. IEEE (1989)

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

  25. Nielson, F., Cousot, P., Dam, M., Degan, P., Jouvelot, P., Mycroft, A., Thomsen, B.: Logical and operational methods in the analysis of programs and systems. In: Dam, M. (ed.) LOMAPS-WS 1996. LNCS, vol. 1192, pp. 1–12. Springer, Heidelberg (1997)

    Chapter  Google Scholar 

  26. Nielson, F., Riis Nielson, H.: Type and Effect Systems. In: Olderog, E.-R., Steffen, B. (eds.) Correct System Design. LNCS, vol. 1710, pp. 114–136. Springer, Heidelberg (1999)

    Chapter  Google Scholar 

  27. Orchard, D., Petricek, T.: Embedding effect systems in Haskell. In: Proceedings of ACM SIGPLAN symposium on Haskell, pp. 13–24. ACM (2014)

    Google Scholar 

  28. Orchard, D.A., Petricek, T., Mycroft, A.: The semantic marriage of monads and effects. CoRR, abs/1401.5391 (2014)

    Google Scholar 

  29. Petricek, T., Mycroft, A., Syme, D.: Extending monads with pattern matching. In: Proceedings of Haskell Symposium, Haskell (2011)

    Google Scholar 

  30. Petricek, T., Orchard, D., Mycroft, A.: Coeffects: unified static analysis of context-dependence. In: Fomin, F.V., Freivalds, R., Kwiatkowska, M., Peleg, D. (eds.) ICALP 2013, Part II. LNCS, vol. 7966, pp. 385–397. Springer, Heidelberg (2013)

    Chapter  Google Scholar 

  31. Petricek, T., Orchard, D., Mycroft, A.: Coeffects: a calculus of context-dependent computation. In: Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, pp. 123–135. ACM (2014)

    Google Scholar 

  32. Petricek, T., Syme, D.: Joinads: a retargetable control-flow construct for reactive, parallel and concurrent programming. In: Rocha, R., Launchbury, J. (eds.) PADL 2011. LNCS, vol. 6539, pp. 205–219. Springer, Heidelberg (2011)

    Chapter  Google Scholar 

  33. Plotkin, G., Power, J.: Notions of computation determine monads. In: Nielsen, M., Engberg, U. (eds.) FOSSACS 2002. LNCS, vol. 2303, pp. 342–356. Springer, Heidelberg (2002)

    Chapter  Google Scholar 

  34. Plotkin, G., Pretnar, M.: A logic for algebraic effects. In: Logic in Computer Science, LICS 2008, pp. 118–129. IEEE (2008)

    Google Scholar 

  35. Rivas, E., Jaskelioff, M., Schrijvers, T.: From monoids to near-semirings: the essence of monadplus and alternative. In: Proceeding of International Symposium on Principles and Practice of Declarative Programming, pp. 196–207. ACM (2015)

    Google Scholar 

  36. Smirnov, A.L.: Graded monads and rings of polynomials. J. Math. Sci. 151(3), 3032–3051 (2008)

    Article  MATH  MathSciNet  Google Scholar 

  37. Talpin, J.P., Jouvelot, P.: The type and effect discipline. In: Logic in Computer Science, LICS 1992, pp. 162–173. IEEE (1992)

    Google Scholar 

  38. Vouillon, J.: Lwt: a cooperative thread library. In: Proceedings of ACM SIGPLAN Workshop on ML, pp. 3–12. ACM, New York (2008)

    Google Scholar 

  39. Wadler, P., Thiemann, P.: The marriage of effects and monads. ACM Trans. Comput. Logic 4, 1–32 (2003)

    Article  MathSciNet  Google Scholar 

Download references

Acknowledgements

We thank Matthew Danish, Ohad Kammar, Shinya Katsumata, Jeremy Yallop, and the anonymous referees for their helpful comments. Any remaining errors are our own. The second author is funded by EPSRC EP/K011715/1 and thanks Nobuko Yoshida for her support.

Author information

Authors and Affiliations

Authors

Corresponding authors

Correspondence to Alan Mycroft or Dominic Orchard .

Editor information

Editors and Affiliations

A Issues Surrounding Monadic Strength

A Issues Surrounding Monadic Strength

A monadic semantics for an effectful simply-typed \(\lambda \)-calculus requires that monads are strong. This captures the idea (implicit in the category of sets, but not in all categories) that a free variable may be captured by an outer \(\lambda \)-binding. Strong monads have an additional operation: \(\mathsf {str}_{A,B} : A \times \mathsf {T}B \rightarrow \mathsf {T}(A \times B)\) satisfying various axioms (see [23, 24]) which amount to saying that the effects encoded in the result of \(\mathsf {str}\) are the effects encoded by the second argument.

The monadic semantics for (bind) in Monad (shown in Sect. 2.3), omitting the type subscripts on \(\mathsf {extend}\) and \(\mathsf {str}\), is then:

The \(\mathsf {str}\) operation turns an environment \(\gamma : {\llbracket {\varGamma }\rrbracket }\) and a result \(\mathsf {T}{\llbracket {\tau }\rrbracket }\) into \(\mathsf {T}({\llbracket {\varGamma }\rrbracket } \times {\llbracket {\tau }\rrbracket }\)) for composition with \(\mathsf {extend} \; {\llbracket {\varGamma , x \!:\! \tau \vdash _{\!M}\ldots }\rrbracket } : \mathsf {T}({\llbracket {\varGamma }\rrbracket } \times {\llbracket {\tau }\rrbracket }) \rightarrow \mathsf {T}{\llbracket {\tau '}\rrbracket }\).

Graded monads can be similarly strong with operation \(\mathsf {str}^F_{A,B} : A \times \mathsf {T}_F B \rightarrow \mathsf {T}_F (A \times B)\), satisfying analogous axioms to the usual strong monad axioms [16]. The graded semantics is then the analogous one to the above.

We might consider adding an effect operation \(\mathsf {S} : \mathcal {F} \rightarrow \mathcal {F}\) corresponding to use of strength in the semantics e.g., \(\mathsf {str}^F_{A,B} : A \times \mathsf {T}_F B \rightarrow \mathsf {T}_{\mathsf {S} F} (A \times B)\). However, an axiom of (non-graded) strong monads is that for all \(x \in A, y \in \mathsf {T}B\) then \(\mathsf {map} \, \mathsf {fst} \, (\mathsf {str}_{A,B} (x, y)) = y\) which for graded strength would imply that \(\mathsf {S} \, F = F\). We accordingly exclude \(\mathsf {S}\) from the effect algebra since it is necessarily identity.

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer International Publishing Switzerland

About this chapter

Cite this chapter

Mycroft, A., Orchard, D., Petricek, T. (2016). Effect Systems Revisited—Control-Flow Algebra and Semantics. In: Probst, C., Hankin, C., Hansen, R. (eds) Semantics, Logics, and Calculi. Lecture Notes in Computer Science(), vol 9560. Springer, Cham. https://doi.org/10.1007/978-3-319-27810-0_1

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-27810-0_1

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-27809-4

  • Online ISBN: 978-3-319-27810-0

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics