How Focusing Resolves Stuck Terms in Core Evaluation

Focusing is a transformation technique in the Core language used to resolve stuck terms by lifting subcomputations. The article compares dynamic and static focusing, explains how they impact evaluation efficiency, and discusses how static focusing simplifies term reductionβ€”despite introducing administrative redexes. The solution is to simplify these redexes during compilation for optimal performance.


This content originally appeared on HackerNoon and was authored by Abstraction: Computer Science Discourse

  1. Introduction

  2. Translating To Sequent Calculus

    2.1 Arithmetic Expressions

    2.2 Let Bindings

    2.3 Top-level Definitions

    2.4 Algebraic Data and Codata Types

    2.5 First-Class Functions

    2.6 Control Operators

  3. Evaluation Within a Context

    3.1 Evaluation Contexts for Fun

    3.2 Focusing on Evaluation in Core

  4. Typing Rules

    4.1 Typing Rules for Fun

    4.2 Typing Rules for Core

    4.3 Type Soundness

  5. Insights

    5.1 Evaluation Contexts are First Class

    5.2 Data is Dual to Codata

    5.3 Let-Bindings are Dual to Control Operators

    5.4 The Case-of-Case Transformation

    5.5 Direct and Indirect Consumers

    5.6 Call-By-Value, Call-By-Name and Eta-Laws

    5.7 Linear Logic and the Duality of Exceptions

  6. Related Work

  7. Conclusion, Data Availability Statement, and Acknowledgments

A. The Relationship to the Sequent Calculus

B. Typing Rules for Fun

C. Operational Semantics of label/goto

References

3.2 Focusing on Evaluation in Core

Let us now come back to the problem in Core and find a solution for the stuck term πœ‡π›Ό. + (πœ‡π›½. βˆ— (⌜2⌝, ⌜4⌝; 𝛽), ⌜5⌝; 𝛼). We know that we have to evaluate πœ‡π›½. βˆ— (⌜2⌝, ⌜4⌝; 𝛽) next and then somehow plug the intermediate result into the hole [Β·] in the producer πœ‡π›Ό. + ( [Β·], ⌜5⌝; 𝛼). If we give the intermediate result the name π‘₯ and play around with cuts, πœ‡-bindings and πœ‡Λœ bindings, we might discover that we can recombine all these parts in the following way:

\ πœ‡π›Ό.βŸ¨πœ‡π›½. βˆ— (⌜2⌝, ⌜4⌝; 𝛽) | πœ‡π‘₯. ˜ + (π‘₯, ⌜5⌝; 𝛼)⟩

\ his term looks a bit mysterious, but the transformation corresponds roughly to what happens when we translate the term let π‘₯ = 2 βˆ— 4 in π‘₯ + 5 instead of (2 βˆ— 4) + 5 into Core. That is, we have lifted a subcomputation to the outside of the term we are evaluating. This kind of transformation is called focusing [Andreoli 1992; Curien and Munch-Maccagnoni 2010] and we use it to solve the problem with stuck terms in Core. We can see that it worked in our example because the term now fully evaluates to its normal form.

\ Example 3.1. The producer πœ‡π›Ό.βŸ¨πœ‡π›½. βˆ— (⌜2⌝, ⌜4⌝; 𝛽) | πœ‡π‘₯. ˜ + (π‘₯, ⌜5⌝; 𝛼)⟩ reduces as follows:

\ βŸ¨πœ‡π›½. βˆ— (⌜2⌝, ⌜4⌝; 𝛽) | πœ‡π‘₯. ˜ + (π‘₯, ⌜5⌝; ⋆)⟩ ⊲ βˆ—(⌜2⌝, ⌜4⌝; πœ‡π‘₯. ˜ + (π‘₯, ⌜5⌝; ⋆))

\ ⊲ ⟨⌜8⌝ | πœ‡π‘₯. ˜ + (π‘₯, ⌜5⌝; ⋆)⟩

\ ⊲ +(⌜8⌝, ⌜5⌝; ⋆) ⊲ ⟨⌜13⌝ | β‹†βŸ©

\ Once we have settled on focusing, we have another choice to make: Do we want to use this trick during the evaluation of a statement or as a preprocessing step before we start with the evaluation? These two alternatives are called dynamic and static focusing.

\ Dynamic Focusing With dynamic focusing [Wadler 2003] we add additional evaluation rules, usually called 𝜍-rules, to lift sub-computations to the outside of the statement we are evaluating.

\ Static Focusing For static focusing [Curien and Herbelin 2000] we perform a transformation on the code before we start evaluating it. This results in a focused normal form which is a subset of the syntax of Core that we have described so far.

\ Dynamic focusing is great for reasoning about the meaning of programs, but static focusing is more efficient if we are interested in compiling and running programs. For this reason, we only consider static focusing in what follows.

\

\ The complete rules for static focusing are presented in Definition 3.2. Most of these rules are only concerned with performing the focusing transformation on all subexpressions, but some of the clauses where something interesting happens are the clauses for binary operators:

\

\ The first two clauses look for the arguments of the binary operator βŠ™ which are not values and use the trick described above to lift them to the outside. Focusing is invoked recursively until the binary operator is only applied to values and the third clause comes into play. This third clause then applies the focusing transformation to all arguments of the binary operator. The clauses for constructors, destructors, ifz and calls to top-level definitions work in precisely the same way as those for binary operators. It is noteworthy that by focusing the producer arguments of destructors we guarantee that the evaluation rule for codata types can fire. If we had not required the producer arguments to be values in that rule (but only that the destructor is a covalue), we could easily introduce an unfocused term again by substituting a non-value for a variable.

\ The focusing transformation described in Definition 3.2 is not ideal since it creates a lot of administrative redexes. As an example, consider how the statement defining mult’ from Example 2.7 is focused:

\ F (βŸ¨π‘™ | case {Nil β‡’ ⟨1 | π›½βŸ©, Cons(π‘₯, π‘₯𝑠) β‡’ ifz(π‘₯, ⟨0 | π›ΌβŸ©, βˆ—(π‘₯, πœ‡π›Ύ .mult’(π‘₯𝑠; 𝛼,𝛾); 𝛽))}⟩)

\ = βŸ¨π‘™ | case {Nil β‡’ ⟨1 | π›½βŸ©, Cons(π‘₯, π‘₯𝑠) β‡’ ifz(π‘₯, ⟨0 | π›ΌβŸ©, βŸ¨πœ‡π›Ύ .mult’(π‘₯𝑠; 𝛼,𝛾) | πœ‡π‘§. ˜ βˆ— (π‘₯, 𝑧; 𝛽)⟩)}⟩

\ Focusing has introduced the administrative redex βŸ¨πœ‡π›Ύ .mult’(π‘₯𝑠; 𝛼,𝛾) | πœ‡π‘§. ˜ βˆ— (π‘₯, 𝑧; 𝛽)⟩ in the second statement of the ifz. After reducing this redex to mult’(π‘₯𝑠; 𝛼, πœ‡π‘§. ˜ βˆ— (π‘₯, 𝑧; 𝛽)), we finally arrive at the result from the introduction. In the implementation, we solve this problem by statically reducing administrative redexes in a simplification step, but it is also possible to come up with a more elaborate definition of focusing which does not create them in the first place. Such an optimized focusing transformation is, however, much less transparent than the one we have described.

\

:::info Authors:

(1) David Binder, University of TΓΌbingen, Germany;

(2) Marco Tzschentke, University of TΓΌbingen, Germany;

(3) Marius Muller, University of TΓΌbingen, Germany;

(4) Klaus Ostermann, University of TΓΌbingen, Germany.

:::


:::info This paper is available on arxiv under CC BY 4.0 license.

:::

\


This content originally appeared on HackerNoon and was authored by Abstraction: Computer Science Discourse


Print Share Comment Cite Upload Translate Updates
APA

Abstraction: Computer Science Discourse | Sciencx (2025-07-08T06:00:08+00:00) How Focusing Resolves Stuck Terms in Core Evaluation. Retrieved from https://www.scien.cx/2025/07/08/how-focusing-resolves-stuck-terms-in-core-evaluation/

MLA
" » How Focusing Resolves Stuck Terms in Core Evaluation." Abstraction: Computer Science Discourse | Sciencx - Tuesday July 8, 2025, https://www.scien.cx/2025/07/08/how-focusing-resolves-stuck-terms-in-core-evaluation/
HARVARD
Abstraction: Computer Science Discourse | Sciencx Tuesday July 8, 2025 » How Focusing Resolves Stuck Terms in Core Evaluation., viewed ,<https://www.scien.cx/2025/07/08/how-focusing-resolves-stuck-terms-in-core-evaluation/>
VANCOUVER
Abstraction: Computer Science Discourse | Sciencx - » How Focusing Resolves Stuck Terms in Core Evaluation. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/08/how-focusing-resolves-stuck-terms-in-core-evaluation/
CHICAGO
" » How Focusing Resolves Stuck Terms in Core Evaluation." Abstraction: Computer Science Discourse | Sciencx - Accessed . https://www.scien.cx/2025/07/08/how-focusing-resolves-stuck-terms-in-core-evaluation/
IEEE
" » How Focusing Resolves Stuck Terms in Core Evaluation." Abstraction: Computer Science Discourse | Sciencx [Online]. Available: https://www.scien.cx/2025/07/08/how-focusing-resolves-stuck-terms-in-core-evaluation/. [Accessed: ]
rf:citation
» How Focusing Resolves Stuck Terms in Core Evaluation | Abstraction: Computer Science Discourse | Sciencx | https://www.scien.cx/2025/07/08/how-focusing-resolves-stuck-terms-in-core-evaluation/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.