arXiv:2609.07667cs.PLSep 2026

Manuscript Offprint

arXiv:2609.07667

A monadic interpreter and type-and-effect checker

Stefano Raviola, Paola Giannini, Francesco Dagnino

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

We present a concrete implementation in Haskell of a monadic framework that includes both a small-step interpreter and a type-and-effect checker for the corresponding language. Our approach separates the language syntax from the semantics of its effects. This design allows the interpreter to remain parametric over the underlying monad, while the static checker approximates effects independently of their concrete implementation.

The theoretical foundation of this framework—applied to a call-by-value lambda calculus with generic effects represented by operations that produce monadic values and are managed through handlers—was introduced in previous work, where the focus was on proving the soundness of the approach. In contrast, the present work leverages Haskell’s support for modular programming and monads to demonstrate that the framework is practically implementable and usable.

We illustrate the approach with examples using the monad of exceptions and the one of nondeterminism and expressions both with and without handlers.

1 Introduction

Moggi’s work [14, 15] established monads as a modular foundation for the denotational semantics of effectful languages, by distinguishing pure expressions from monadic (effectful) computations. Haskell first¹ showed that this approach scales to mainstream programming via a monadic type constructor encapsulating effects. However, monads² do not intrinsically provide operations for raising effects, which must be defined ad hoc. Algebraic and generic effects [17–19] address this limitation by making effect operations explicit and interpreting them through additional monadic structure. This approach, combined with handlers [1, 20–22], has been exploited in programming languages, e.g., in Scala and OCaml 5.

Operational semantics describes how a program is executed. It typically comes in two forms: big-step semantics, which

reduces expressions directly to their final values, and small-step semantics, which describes computation as a sequence of atomic reduction steps. While big-step semantics is often simpler for defining interpreters, small-step semantics is the preferred choice when establishing properties such as type soundness, see Wright and Felleisen [27].

In Dagnino et al. [5], a novel approach to statically reason not only about results but also about the effects that computations may produce is proposed, which builds on the two foundational ideas in programming language theory: the use of monads to model computational effects, as introduced by Moggi, and the operational approach to type soundness based on progress and subject reduction. The type system is extended to a type-and-effect system, and an operational meta-theory of monadic type-and-effect soundness is developed, analogous to the classical small-step framework for type soundness. Program expressions reduce deterministically to monadic expressions, and this reduction is extended to a total function so that reduction steps compose via Kleisli composition. As a result, computations yield infinite reduction sequences, with termination represented by special monadic results that do not raise further effects.

In this paper, we describe a Haskell implementation of a type-and-effect checker and a small-step interpreter for an extension of the lambda calculus with generic effects and effect handlers of Dagnino et al. [5]. The modules separate the generic framework from the specific language and algebraic effects. Examples of tracking exceptions and controlling nondeterminism are implemented. The tool provides a front-end that can be used to specify the monad for interpreting the effects raised by the execution of the effectful operations and the expression to be evaluated.

The implementation has the following properties.

  • The reduction engine is parametric over the underlying monad. It executes the “effectful operations” by delegating their execution to an abstract interface, so that the runtime behavior can change, e.g., from exceptions to non-determinism, without modifying the core rules.

¹Later followed by many other languages, including Scheme, Python, Racket, Scala, and F#.

²In Haskell, the methods of the Monad typeclass.

S. Raviola, P. Giannini, F. Dagnino

  • The type-and-effect checker infers both types and effects and checks that they are compatible with the ones specified in the expression. The abstract effect types are instantiated as sets of effectful operations.

The implementation aims to show that the theoretical framework can be used to provide a practical embedding of generic effects in a programming language. To achieve this, the language introduced by Dagnino et al. [5] is extended with a conditional construct. This extension requires the addition of a subtyping relation on base types, as well as the inclusion of meet and join operators in the algebraic structure of effect types.

Outline of the paper. In Section 2 we present the definitions underlying the monadic interpreter and type-and-effect checker. ΛΣ\Lambda_\Sigma with its operational semantics and type system are introduced in Section 3. Section 4 contains a description of the Haskell implementation with an outline of its modules, and two examples of the small-step monadic reduction are given in Section 5. In Section 6 we compare with other proposals of similar work and finally Section 7 draws some conclusions and outlines future work.

Sections 2 and 3 present material largely drawn from Dagnino et al. [5]. The language and type-and-effect system described in Section 3 extend that of [5] by introducing a conditional construct, meet and join operators on types and a richer algebraic structure for effect types. Moreover, the abstract effect type structure is instantiated on sets of operations. The remaining sections are original.

References (19)