Notions of Stack-manipulating Computation and Relative Monads (Extended Version)

📅 2025-02-20
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
This paper addresses the disconnect between monadic abstractions and explicit stack manipulation in higher-order functional languages. We propose a stack-aware effect modeling methodology based on the call-by-push-value (CBPV) calculus. Our key contributions are threefold: (1) the first formalization of stack-manipulation effects using relative monads; (2) the design of “monadic blocks”—syntactic sugar generalizing Haskell’s do-notation to support customizable stack layouts; and (3) an automated lifting mechanism from relative monads to relative monad transformers, circumventing the theoretical impossibility of constructing monad transformers in purely functional settings. The resulting type system supports effect implementations over arbitrary stack layouts, enables faithful migration of standard monads, and provides a compositional, reasoning-friendly effect abstraction framework for compiler backends and assembly-level code generation. (138 words)

Technology Category

Application Category

📝 Abstract
Monads provide a simple and concise interface to user-defined computational effects in functional programming languages. This enables equational reasoning about effects, abstraction over monadic interfaces and the development of monad transformer stacks to combine different effects. Compiler implementors and assembly code programmers similarly virtualize effects, and would benefit from similar abstractions if possible. However, the implementation details of effects seem disconnected from the high-level monad interface: at this lower level much of the design is in the layout of the runtime stack, which is not accessible in a high-level programming language. We demonstrate that the monadic interface can be faithfully adapted from high-level functional programming to a lower level setting with explicit stack manipulation. We use a polymorphic call-by-push-value (CBPV) calculus as a setting that captures the essence of stack-manipulation, with a type system that allows programs to define domain-specific stack structures. Within this setting, we show that the existing category-theoretic notion of a relative monad can be used to model the stack-based implementation of computational effects. To demonstrate generality, we adapt a variety of standard monads to relative monads. Additionally, we show that stack-manipulating programs can benefit from a generalization of do-notation we call"monadic blocks"that allow all CBPV code to be reinterpreted to work with an arbitrary relative monad. As an application, we show that all relative monads extend automatically to relative monad transformers, a process which is not automatic for monads in pure languages.
Problem

Research questions and friction points this paper is trying to address.

Adapt monadic interface to stack manipulation
Model stack-based effects using relative monads
Generalize do-notation for stack-manipulating programs
Innovation

Methods, ideas, or system contributions that make the work stand out.

Adapts monadic interface to stack manipulation
Uses CBPV calculus for stack structures
Introduces monadic blocks for CBPV code
🔎 Similar Papers
2022-12-16International Conference on Formal Structures for Computation and DeductionCitations: 3
Yuchen Jiang
Yuchen Jiang
Alibaba Group
R
Runze Xue
Computer Science and Engineering, University of Cambridge, GB
Max S. New
Max S. New
Computer Science and Engineering, University of Michigan, USA