Hostname: page-component-89b8bd64d-n8gtw Total loading time: 0 Render date: 2026-05-07T21:29:32.496Z Has data issue: false hasContentIssue false

A type-directed, dictionary-passing translation of method overloading and structural subtyping in Featherweight Generic Go

Published online by Cambridge University Press:  09 October 2023

MARTIN SULZMANN
Affiliation:
Karlsruhe University of Applied Sciences, Karlsruhe, Germany (e-mail: martin.sulzmann@h-ka.de)
STEFAN WEHR
Affiliation:
Offenburg University of Applied Sciences, Offenburg, Germany (e-mail: stefan.wehr@hs-offenburg.de)
Rights & Permissions [Opens in a new window]

Abstract

Featherweight Generic Go (FGG) is a minimal core calculus modeling the essential features of the programming language Go. It includes support for overloaded methods, interface types, structural subtyping, and generics. The most straightforward semantic description of the dynamic behavior of FGG programs is to resolve method calls based on runtime type information of the receiver. This article shows a different approach by defining a type-directed translation from ${\textrm{FGG}^{-}}$ to an untyped lambda-calculus. ${\textrm{FGG}^{-}}$ includes all features of FGG but type assertions. The translation of an ${\textrm{FGG}^{-}}$ program provides evidence for the availability of methods as additional dictionary parameters, similar to the dictionary-passing approach known from Haskell type classes. Then, method calls can be resolved by a simple lookup of the method definition in the dictionary. Every program in the image of the translation has the same dynamic semantics as its source ${\textrm{FGG}^{-}}$ program. The proof of this result is based on a syntactic, step-indexed logical relation. The step index ensures a well-founded definition of the relation in the presence of recursive interface types and recursive methods. Although being non-deterministic, the translation is coherent.

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

Fig. 1. String-formatting and its translation.

Figure 1

Fig. 2. String-formatting with generics (extending code from Figure 1).

Figure 2

Fig. 3. Bounded type parameters of methods (extending code from Figure 2).

Figure 3

Fig. 4. Bounded type parameters of structs and interfaces (extending code from Figure 1).

Figure 4

Fig. 5. Syntax of ${\textrm{FGG}^{-}}$.

Figure 5

Fig. 6. Dynamic semantics of ${\textrm{FGG}^{-}}$.

Figure 6

Fig. 7. Target language (TL).

Figure 7

Fig. 8. Auxiliary judgments for the translation.

Figure 8

Fig. 9. Translation of structural subtyping.

Figure 9

Fig. 10. Translation of expressions.

Figure 10

Fig. 11. Well-formedness.

Figure 11

Fig. 12. Translation of methods and programs.

Figure 12

Fig. 13. Example: ${\textrm{FGG}^{-}}$ code (top) and its translation (middle) with abbreviations (bottom).

Figure 13

Fig. 14. Example: translation of the method declaration for $\mathit{Box}$ and $\mathit{eq}$.

Figure 14

Fig. 15. Example: translation of the main function.

Figure 15

Fig. 16. Relating ${\textrm{FGG}^{-}}$ to TL expressions.

Figure 16

Fig. 17. Relating ${\textrm{FGG}^{-}}$ to TL substitutions and declarations.

Figure 17

Fig. 18. Erasure of dictionaries.

Figure 18

Fig. 19. Summary of the test suite for the implementation.

Figure 19

Fig. 20. Summary of translations. Arrows represent translations, and $P_{\ell}$ is a program in language $\ell$. Program $P_{\textrm{FGG}^{\star}}$ is subject to certain restrictions, depending on the translation being performed.

Supplementary material: File

Sulzmann and Wehr supplementary material

Sulzmann and Wehr supplementary material

Download Sulzmann and Wehr supplementary material(File)
File 1.9 MB
Submit a response

Discussions

No Discussions have been published for this article.