Hostname: page-component-6766d58669-mzsfj Total loading time: 0 Render date: 2026-05-17T01:33:59.754Z Has data issue: false hasContentIssue false

From high to low: Simulating nondeterminism and state with state

Published online by Cambridge University Press:  03 January 2025

WENHAO TANG
Affiliation:
The University of Edinburgh, Edinburgh, UK (e-mail: wenhao.tang@ed.ac.uk)
TOM SCHRIJVERS
Affiliation:
Department of Computer Science, KU Leuven, Leuven, Belgium (e-mail: tom.schrijvers@kuleuven.be)
Rights & Permissions [Opens in a new window]

Abstract

Some effects are considered to be higher level than others. High-level effects provide expressive and succinct abstraction of programming concepts, while low-level effects allow more fine-grained control over program execution and resources. Yet, often it is desirable to write programs using the convenient abstraction offered by high-level effects, and meanwhile still benefit from the optimizations enabled by low-level effects. One solution is to translate high-level effects to low-level ones.

This paper studies how algebraic effects and handlers allow us to simulate high-level effects in terms of low-level effects. In particular, we focus on the interaction between state and nondeterminism known as the local state, as provided by Prolog. We map this high-level semantics in successive steps onto a low-level composite state effect, similar to that managed by Prolog’s Warren Abstract Machine. We first give a translation from the high-level local-state semantics to the low-level global-state semantics, by explicitly restoring state updates on backtracking. Next, we eliminate nondeterminism altogether in favour of a lower-level state containing a choicepoint stack. Then we avoid copying the state by restricting ourselves to incremental, reversible state updates. We show how these updates can be stored on a trail stack with another state effect. We prove the correctness of all our steps using program calculation where the fusion laws of effect handlers play a central role.

Information

Type
Research Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2025. Published by Cambridge University Press
Figure 0

Table 1: Overview of translations from high-level effects to low-level effects in the paper

Figure 1

Fig. 1: State-restoring put-operation.

Figure 2

Table 2: Comparing put and ${put}_{R}$

Figure 3

Fig. 2: Auxiliary functions ${{pop_S}}$, ${{push_S,}}$ and ${{append_S}}$.

Figure 4

Fig. 3: Auxiliary functions ${{pop}_{{SS}}}$, ${{push}_{{SS}}}$ and ${{append}_{{SS}}}$.

Figure 5

Fig. 4: An overview of the simulate function.

Figure 6

Fig. 5: An overview of the ${{simulate_T}}$ function.

Submit a response

Discussions

No Discussions have been published for this article.