An Effectful Object Calculus

Francesco Dagnino, Paola Giannini, Elena Zucca · 2025

Read An Effectful Object Calculus by Francesco Dagnino, Paola Giannini, Elena Zucca (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2504-15936.txt.

Introduction

Francesco Dagnino, Paola Giannini, and Elena Zucca build a formal language for object based programs that can raise and handle effects, in a paper from 2025. Effects here mean acts such as raising a signal that other code must deal with, framed in a broad math form.

In their design, raising an effect is just a special method call, so plain programmers can use it with ease. Types track which effects code may raise, with the help of class links and generic types. The authors prove core safety traits for the system, showing that well typed programs step in sound ways.

Catalog record

CREATORFrancesco Dagnino, Paola Giannini, Elena Zucca
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE184 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2504-15936

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

An Effectful Object Calculus Francesco Dagnino, Paola Giannini, Elena Zucca Abstract We show how to smoothly incorporate in the object-oriented paradigm constructs to raise, compose, and handle effects in an arbitrary monad. The underlying pure calculus is meant to be a representative of the last generation of OO languages, and the effectful extension is manageable enough for ordinary programmers; notably, constructs to raise effects are just special methods. We equip the calculus with an expressive type-and-effect system, which, again by relying on standard features such as inheritance and generic types, allows a simple form of effect polymorphism. The soundness of the type-and-effect system is expressed and proved by a recently introduced technique, where the semantics is formalized by a one-step reduction relation from language expressions into monadic ones, so that it is enough to prove progress and subject reduction properties on this relation. DIBRIS, Università di Genova, [email protected]://orcid.org/0000-0003-3599-3535 DiSSTE, Università del Piemonte Orientale, [email protected]://orcid.org/0000-0003-2239-9529 DIBRIS, Università di Genova, [email protected]://orcid.org/0000-0002-6833-6470 {CCSXML} ¡ccs2012¿ ¡concept¿ ¡concept_id¿10003752.10010124.10010125.10010130¡/concept_id¿ ¡concept_desc¿Theory of computation Type structures¡/concept_desc¿ ¡concept_significance¿500¡/concept_significance¿ ¡/concept¿ ¡/ccs2012¿ {CCSXML} ¡concept¿ ¡concept_id¿10003752.10010124.10010131.10010134¡/concept_id¿ ¡concept_desc¿Theory of computation Operational semantics¡/concept_desc¿ ¡concept_significance¿500¡/concept_significance¿ ¡/concept¿ ¡/ccs2012¿ \lstset basicstyle= , showspaces=false, showstringspaces=false, mathescape=true ccs Theory of computation Operational semantics ccs Theory of computation Type structures keywords Object calculi, handlers, type-and-effect systems † † runningauthor: F. Dagnino, P. Giannini, and E. Zucca † † copyright: Francesco Dagnino, Paola Giannini, and Elena Zucca † † funding: This work was partially funded by the MUR project “T-LADIES” (PRIN 2020TL3X8X) and has the financial support of the Università del Piemonte Orientale. † † editors: John Q. Open and Joan R. Access † † event-title: 42nd Conference on Very Important Topics (CVIT 2016) † † event-shorttitle: CVIT 2016 † † event-acronym: CVIT † † year: 2016 † † event-date: December 24–27, 2016 † † event-location: Little Whinging, United Kingdom † † series-volume: 42 † † articleno: 23 1 Introduction Every modern programming language needs to support a wide range of computational effects, such as exceptions, input/output, interaction with a memory and classical or probabilistic non-determinism. Several approaches have been proposed for designing language constructs dealing with different computational effects in a uniform and principled way. The monad pattern [ 30 , 31 , 46 ] and algebraic effects and handlers [ 33 , 34 , 35 , 37 , 38 , 5 , 40 ] stand out for their impact on real world programming, and are now incorporated into many mainstream languages such as Haskell, OCaml 5 and Scala. However, this area of research focuses on the functional paradigm. The aim of this paper, instead, is to show that constructs to raise, compose, and handle effects can be smoothly incorporated into object-oriented languages; in fact, the specific features of the paradigm help in allowing a simple effectful extension. We illustrate the effectful extension on top of a pure object calculus, meant to be an evolution of Featherweight Java (FJ) 1 1 1 In its version with generic types. [ 20 ] , for more than twenty years the paradigmatic calculus for Java-like languages. Indeed, like FJ it only includes distinctive ingredients, such as nominal types, inheritance, and objects, and no imperative features. However, following the current trend in OO languages, and inspired by recent work [ 49 , 42 , 50 ] , object values are, rather than class instances with fields, object literals , extending a sequence of nominal types with additional methods. In other words, we select, as subset of Java features, interfaces with default methods and anonymous classes, rather than classes with fields and constructors. This choice leads to generality, in the sense that the language design encompasses both Java-like and functional calculi. More precisely, FJ can be easily encoded by representing fields as constant methods, and, at the same time, the simply-typed lambda calculus can be seen as a language subset, since functions are a special case of stateless objects. The effectful extension builds on generic effects [ 35 ] and handlers [ 37 ] , carefully adapted to be more familiar to OO programmers. Constructs for raising effects are just method calls of a special kind, called magic . 2 2 2 This terminology is taken from [ 50 ] , and also informally used in Java reflection and Python. They are made available through predefined interfaces, and do not specify an implementation, like abstract ones. However, rather than being deferred to subtypes, their implementation is provided “by the system”. For instance, throwing an exception is a magic call \lstinline Exception.throw(). This fits naturally in the OO paradigm, where computations happen in the context of a program. Again to be familiar, the construct to handle effects is a generalized try-block with catch clauses. A raised effect (a magic call) is caught by a clause when the receiver’s type is (a subtype of) that specified in the clause, as for Java exceptions, generalized to arbitrary magic calls. To this end, besides those interrupting the normal flow of execution, we allow catch clauses replacing an effect with an alternative behaviour in a continuous manner. Altogether, the construct provides a good compromise between simplicity and expressivity: notably, it does not explicitly handle continuations, as in handlers of algebraic effects [ 37 , 38 , 23 , 18 ] , yet expressing a variety of handling mechanisms. We endow our calculus with a type-and-effect system where effect types 3 3 3 The term “effect” is used in literature both as synonym of computational effect, and in the context of type-and-effect systems, as a static approximation of the former. We will use “effect” when there is no ambiguity, otherwise “computational effect” and “effect type”, respectively. again generalize sets of exceptions, as in \lstinline throws clauses, to sets of call-effects , of shape \mathit{T}.\mathsf{m}[\overline{\mathit{T}}] , approximating the computational effects of a call of \mathsf{m} in type \mathit{T} , with types \overline{\mathit{T}} instantiating the type variables of the method. This approach, inspired by [ 14 ] , provides more expressivity than the effect systems for algebraic effects [ 4 , 5 , 40 ] , which only track the names of operations raising effects, without any type information. Moreover, \mathit{T} can be a type variable \mathit{X} , expressing a call-effect not yet specified, which will become, when \mathit{X} is instantiated to a specific type, the effect type declared there for the method. This allows a rather sophisticated approximation of effects, encompassing a simple form of effect polymorphism [ 25 , 19 , 28 , 6 , 8 , 7 ] . Last but not least, the soundness of the type-and-effect system is expressed and proved by a newly introduced approach [ 10 ] , building on a recent line of research on monadic operational semantics for effectful languages [ 16 , 17 ] . That is, the semantics is formalized by a one-step reduction from language expressions into monadic ones, parameterized by a monad modeling the capabilities provided by the system. In this way, we can uniformly deal with a wide range of effects, by just providing an interpretation of magic methods in the monad. Then, applying a technique from [ 10 ] , to ensure type-and-effect soundness it is enough to prove progress and subject reduction on the monadic one-step reduction.

Read the complete text