Hostname: page-component-5db58dd55d-lqwgf Total loading time: 0 Render date: 2026-07-08T16:32:15.218Z Has data issue: false hasContentIssue false

Type-directed operational semantics for gradual typing

Published online by Cambridge University Press:  26 September 2024

WENJIA YE
Affiliation:
The University of Hong Kong, Hong Kong, China, (e-mail: wjye@cs.hku.hk)
BRUNO C. D. S. OLIVEIRA
Affiliation:
The University of Hong Kong, Hong Kong, China, (e-mail: bruno@cs.hku.hk)
Rights & Permissions [Opens in a new window]

Abstract

The semantics of gradually typed languages is typically given indirectly via an elaboration into a cast calculus. This contrasts with more conventional formulations of programming language semantics, where the semantics of a language is given directly using, for instance, an operational semantics. This paper presents a new approach to give the semantics of gradually typed languages directly. We use a recently proposed variant of small-step operational semantics called type-directed operational semantics (TDOS). In a TDOS, type annotations become operationally relevant and can affect the result of a program. In the context of a gradually typed language, type annotations are used to trigger type-based conversions on values. We illustrate how to employ a TDOS on gradually typed languages using two calculi. The first calculus, called $\lambda B^{g}$, is inspired by the semantics of the blame calculus, but it has implicit type conversions, enabling it to be used as a gradually typed language. The second calculus, called $\lambda e$, explores an eager semantics for gradually typed languages using a TDOS. For both calculi, type safety is proved. For the $\lambda B^{g}$ calculus, we also present a variant with blame labels and illustrate how the TDOS can also deal with such an important feature of gradually typed languages. We also show that the semantics of $\lambda B^{g}$ with blame labels is sound and complete with respect to the semantics of the blame calculus, and that both calculi come with a gradual guarantee. All the results have been formalized in the Coq theorem prover.

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), 2024. Published by Cambridge University Press
Figure 0

Fig. 1. The $\lambda B$ calculus (selected rules).

Figure 1

Fig. 2. Syntax and well-formed values for the $\lambda B^{g}$ calculus.

Figure 2

Fig. 3. Type system of the $\lambda B^{g}$ calculus.

Figure 3

Fig. 4. Casting for the $\lambda B^{g}$ calculus.

Figure 4

Fig. 5. Semantics of $\lambda B^{g}$.

Figure 5

Fig. 6. Static semantics for the $\lambda B^{g}_{l}$ calculus.

Figure 6

Fig. 7. Casting for the $\lambda B^{g}_{l}$ calculus.

Figure 7

Fig. 8. Semantics of $\lambda B^{g}_{l}$.

Figure 8

Fig. 9. New reduction steps.

Figure 9

Fig. 10. Decomposition of reduction steps.

Figure 10

Fig. 11. Elaboration between $\lambda B^{g}_{l}$ and $\lambda B$.

Figure 11

Fig. 12. Precision relations.

Figure 12

Fig. 13. Safe expressions of $\lambda B^{g}_{l}$.

Figure 13

Fig. 14. Syntax of the $\lambda e$ calculus.

Figure 14

Fig. 15. Typing rules for $\lambda e$.

Figure 15

Fig. 16. Casting for the $\lambda e$ calculus.

Figure 16

Fig. 17. Semantics of the $\lambda e$ calculus.

Figure 17

Fig. 18. Precision relations.

Supplementary material: File

Ye and Oliveira supplementary material

Ye and Oliveira supplementary material

Download Ye and Oliveira supplementary material(File)
File 1.7 MB
Submit a response

Discussions

No Discussions have been published for this article.