[Paper Review] A Lightweight Combination of Semantics for Non-deterministic Functions
This paper proposes a lightweight extension to functional logic languages that combines call-time choice and run-time choice semantics within a single program, using a simple 'rt' annotation to disable sharing for specific sub-expressions. The approach is efficiently implemented in the Toy system by modifying suspension handling, enabling both semantics to coexist without breaking existing call-time choice behavior.
The use of non-deterministic functions is a distinctive feature of modern functional logic languages. The semantics commonly adopted is call-time choice, a notion that at the operational level is related to the sharing mechanism of lazy evaluation in functional languages. However, there are situations where run-time choice, closer to ordinary rewriting, is more appropriate. In this paper we propose an extension of existing call-time choice based languages, to provide support for run-time choice in localized parts of a program. The extension is remarkably simple at three relevant levels: syntax, formal operational calculi and implementation, which is based on the system Toy.
Motivation & Objective
- Address the limitation in existing functional logic systems that enforce a single non-determinism semantics (either call-time or run-time choice) across the entire program.
- Enable programmers to selectively apply run-time choice to specific sub-expressions where it is more appropriate, such as in grammar rules or repeated generators.
- Provide a practical extension to existing call-time choice-based systems like Toy and Curry, minimizing implementation complexity.
- Formally define the semantics of the extended language using operational calculi and logical proof systems to support correctness and analysis.
- Demonstrate that the combination allows for more expressive and correct program behavior in cases where pure call-time or run-time choice fails, such as in palindrome generation and digit combination generation.
Proposed method
- Introduce a new unary function symbol 'rt' to annotate expressions, signaling that their evaluation should follow run-time choice semantics and avoid sharing.
- Modify the suspension mechanism in the Toy system to track whether a suspended expression is subject to sharing (call-time) or not (run-time), using a flag in the suspension data structure.
- Define two variants of the extension: a local variant where 'rt(e)' affects only the evaluation of e, and a global variant where 'rt' annotations are treated as a scope for run-time choice.
- Adapt two one-step reduction relations from prior work to model the new operational behavior under the extended semantics.
- Provide a logical semantics based on the CRWL framework, extending its proof calculus to handle 'rt' annotations and ensuring consistency with the operational model.
- Implement the local variant in the Toy system by modifying suspension management, demonstrating feasibility and performance in practice.
Experimental results
Research questions
- RQ1Can a practical and lightweight mechanism be designed to combine call-time and run-time choice semantics in a single functional logic program?
- RQ2How can run-time choice be selectively applied to specific sub-expressions without disrupting the existing call-time choice infrastructure?
- RQ3What formal operational and logical semantics can accurately describe the behavior of programs using mixed choice semantics?
- RQ4Is it feasible to implement such a combination in an existing Prolog-based functional logic system like Toy without major architectural changes?
- RQ5Can the proposed extension correctly handle real-world examples where pure call-time or run-time choice fails, such as in grammar-based string generation or digit combination problems?
Key findings
- The 'rt' annotation successfully disables sharing for specific sub-expressions, enabling run-time choice behavior where needed, such as in the definition of 'word' using 'star(rt(letter))'.
- The prototype implementation in Toy correctly generates all 27 combinations of digits 0, 1, and 2 in 'number 3' when using 'rt(0 | 1 | 2)', whereas call-time choice would only produce [0,0,0], [1,1,1], and [2,2,2].
- The system correctly produces the value 1 for 'test2 = rt(double coin)' by evaluating the two calls to 'coin' independently, which is impossible under standard call-time choice.
- The extension allows the palindrome generator to work correctly by preserving sharing for 'word' in 'palAux(word)', while enabling independent evaluation in 'star(rt(letter))' for 'word'.
- The formal operational calculi and logical semantics provide a sound foundation for reasoning about programs with mixed choice semantics, with the local variant being directly implementable.
- The mapping from the global variant to the local variant enables implementation of the more abstract global semantics using the simpler local mechanism.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.