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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
Notes
- 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.
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.
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 A, B instead of \(\tau ,\tau '\) above) and the categorical objects A, B which model them (more formally \({\llbracket {\tau }\rrbracket },{\llbracket {\tau '}\rrbracket }\)).
- 4.
We use \([-]\) for translation into another language and reserve \(\llbracket - \rrbracket \) for semantic interpretation (denotation) as in the next section.
- 5.
Katsumata uses ‘pre-ordered’ but we simply consider \((\sqsubseteq )\cap (\sqsubseteq ^{-1})\) equivalence classes.
- 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.
Categorically, a natural transformation, derived from coproducts with \(\mathbb {B} = 1 + 1\).
- 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
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)
Amtoft, T., Nielson, F., Nielson, H.: Type and Effect Systems Behaviours for Concurrency. Imperial College Press (1999)
Atkey, R.: Parameterised notions of computation. Cambridge University Press. In: Proceedings of MSFP (2006)
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)
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)
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)
Flanagan, C., Qadeer, S.: A type and effect system for atomicity. In: Proceedings of PLDI 2003. ACM (2003)
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)
Gifford, D.K., Lucassen, J.M.: Integrating functional and imperative programming. In: Proceedings of Conference on LISP and Functional Programming, LFP 1986 (1986)
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)
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)
Jouvelot, P., Gifford, D.K.: Communication Effects for Message-Based Concurrency. Technical report, Massachusetts Institute of Technology (1989)
Jouvelot, P., Gifford, D.K.: Reasoning about continuations with control effects. In: Proceedings of PLDI 1989. ACM (1989)
Kammar, O.: Algebraic theory of type-and-effect systems, Ph.D. dissertation. The University of Edinburgh (2014)
Kammar, O., Plotkin, G.D.: Algebraic foundations for effect-dependent optimisations. In: Proceedings of POPL 2012, pp. 349–360. ACM (2012)
Katsumata, S.: Parametric effect monads and semantics of effect systems. In: Proceedings of POPL 2014, pp. 633–645. ACM (2014)
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)
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)
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)
Mellies, P.A.: Parametric monads and enriched adjunctions (2012) http://www.pps.univ-paris-diderot.fr/mellies/tensorial-logic.html
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)
Milner, R.: Communication and Concurrency, vol. 84. Prentice Hall, New York (1989)
Moggi, E.: Computational lambda-calculus and monads. In: Fourth Annual Symposium on Logic in Computer Science, pp. 14–23. IEEE (1989)
Moggi, E.: Notions of computation and monads. Inf. Comput. 93(1), 55–92 (1991)
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)
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)
Orchard, D., Petricek, T.: Embedding effect systems in Haskell. In: Proceedings of ACM SIGPLAN symposium on Haskell, pp. 13–24. ACM (2014)
Orchard, D.A., Petricek, T., Mycroft, A.: The semantic marriage of monads and effects. CoRR, abs/1401.5391 (2014)
Petricek, T., Mycroft, A., Syme, D.: Extending monads with pattern matching. In: Proceedings of Haskell Symposium, Haskell (2011)
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)
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)
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)
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)
Plotkin, G., Pretnar, M.: A logic for algebraic effects. In: Logic in Computer Science, LICS 2008, pp. 118–129. IEEE (2008)
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)
Smirnov, A.L.: Graded monads and rings of polynomials. J. Math. Sci. 151(3), 3032–3051 (2008)
Talpin, J.P., Jouvelot, P.: The type and effect discipline. In: Logic in Computer Science, LICS 1992, pp. 162–173. IEEE (1992)
Vouillon, J.: Lwt: a cooperative thread library. In: Proceedings of ACM SIGPLAN Workshop on ML, pp. 3–12. ACM, New York (2008)
Wadler, P., Thiemann, P.: The marriage of effects and monads. ACM Trans. Comput. Logic 4, 1–32 (2003)
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
Corresponding authors
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
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)