Papers
Topics
Authors
Recent
Gemini 2.5 Flash
Gemini 2.5 Flash 99 tok/s
Gemini 2.5 Pro 48 tok/s Pro
GPT-5 Medium 40 tok/s
GPT-5 High 38 tok/s Pro
GPT-4o 101 tok/s
GPT OSS 120B 470 tok/s Pro
Kimi K2 161 tok/s Pro
2000 character limit reached

Flattening subtyping by eta expansion (2412.19053v1)

Published 26 Dec 2024 in cs.PL

Abstract: To design type systems that use subtyping, we have to make tradeoffs. Deep subtyping is more expressive than shallow subtyping, because deep subtyping compares the entire structure of types. However, shallow subtyping is easier to reason about. By eta-expanding source programs, we can get the effect of deep subtyping with less of its complexity. An early paper on filter models (Barendregt et al. 1983) examined two similar intersection type systems. The first included a subsumption rule that used a rich subtyping relation, including multiple rules for the top type and a distributivity rule. Their second type system dropped the subsumption rule, but added a rule that allowed a term to be eta-expanded before typing it. This rule in their second type system compensated for the lack of subsumption: where their first type system used subtyping to manipulate intersections deep inside types, their second type system used introduction and elimination rules directly on the subterms created by eta-expansion. Viewed as a computation, their proof of completeness for the second (shallow) system performs eta-expansion. Thus, we can regard their proof as inventing the application of eta-expansion to avoid deep subtyping. This paper serves as a tutorial on using eta-expansion to obviate deep subtyping, puts the invention of the technique by Barendregt et al. (1983) into context, gives a complete proof of the relevant lemma, and discusses how the technique can be used in type system design.

List To Do Tasks Checklist Streamline Icon: https://streamlinehq.com

Collections

Sign up for free to add this paper to one or more collections.

Summary

  • The paper presents a method using eta expansion to simulate deep subtyping through the simpler shallow subtyping strategy.
  • It formalizes eta expansion rules and proofs to ensure that transformed terms remain valid under shallow subtyping.
  • The approach enables practical type system design by balancing the expressiveness of deep subtyping with simplified reasoning and implementation.

Flattening Subtyping by Eta Expansion

Introduction

In the design of type systems that incorporate subtyping, a crucial decision involves choosing between deep and shallow subtyping strategies. Deep subtyping, which considers the entire structure of the types involved, is more expressive but complicates reasoning and implementation efforts. On the other hand, shallow subtyping only examines type heads, simplifying reasoning and implementation at the cost of expressiveness.

The paper "Flattening subtyping by eta expansion" outlines a method to simulate deep subtyping via eta-expansion, which transforms programs to obtain the expressiveness of deep subtyping while employing the simpler reasoning of shallow subtyping. This is achieved by expanding terms to capture the full effect of deep subtyping in a structurally simpler setting.

Type System Overview

The simply typed lambda calculus forms the basis for this exploration, augmented with products, booleans, and numeric types. The subtyping mechanism covers basic numerical and boolean types, with subtyping rules designed to demonstrate the effect of both shallow and deep subtyping. Specifically, intint types are considered subtypes of ratrat types, illustrating the numeric tower abstraction frequently used in type systems.

Deep Subtyping: Allows type coercion within composite types (e.g., function types and product types) by decomposing them into their constituent parts. This approach ensures compatibility when treating one data type as an instance of another, more general type.

1
2
3
4
5
Deep Subtyping Rules:
A :< A
int :< rat
(A1 -> A2) :< (B1 -> B2) if B1 :< A1 and A2 :< B2
(A1 * A2) :< (B1 * B2) if A1 :< B1 and A2 :< B2

Shallow Subtyping: Simplifies comparison by restricting to comparisons at the type head level, using simple reflexivity and explicitly listed conversion rules.

1
2
3
Shallow Subtyping Rules:
A :<: A
int :<: rat

Eta Expansion

Eta-expansion in this context acts to bridge the gap between the expressiveness of deep subtyping and the simplicity of shallow reasoning. It allows programs initially designed with deep subtyping in mind to be transformed into equivalent forms in a shallow typing environment, preserving correctness and expressiveness without incurring the complexity burden of deep reasoning.

Eta Expansion Rules:

1
2
- Function: λx.(e x) transforms to e when x not free in e
- Product: (e.1, e.2) transforms to e

Eta-reduction is the process of transforming λx.(f x) back to f when </code>isnotwithin<code>f</code>,allowingreversecomputationpathwaystofacilitatereasoningbetweentheexpressivenessoffulltypestructuresandtheirheadrepresentations.</p><h3class=paperheadingid=lemmaandtheoremofetaexpansion>LemmaandTheoremofEtaExpansion</h3><p>Thecriticalcontributionliesinaformalproofthatetaexpansionmaintainsthecompletenessofatypesystemwithdeepsubtypingwhentransitioningtoashallowsubtypingsystem.Thetechnicallemmashowsthatshallowsystemscanprocessdeepsubtypingcorrectlywhentermsareappropriatelyetaexpanded.</p><p><strong>LemmaShallowExpansion</strong>:</p><p>Ifatype</code> is not within <code>f</code>, allowing reverse computation pathways to facilitate reasoning between the expressiveness of full type structures and their head representations.</p> <h3 class='paper-heading' id='lemma-and-theorem-of-eta-expansion'>Lemma and Theorem of Eta Expansion</h3> <p>The critical contribution lies in a formal proof that eta-expansion maintains the completeness of a type system with deep subtyping when transitioning to a shallow subtyping system. The technical lemma shows that shallow systems can process deep subtyping correctly when terms are appropriately eta-expanded.</p> <p><strong>Lemma - Shallow Expansion</strong>:</p> <p>If a type Aisadeepsubtypeof is a deep subtype of Bandaterm and a term ehastype has type A,thenthereexistsanetaexpandedterm, then there exists an eta-expanded term e'suchthat such that e'isconvertibleto is convertible to eandisvalidundertype and is valid under type B$ in a shallow subtyping context.

Practical Applications

This transformation technique offers a practical methodology for programming language and type system designers aiming to leverage the expressiveness of deep subtyping while opting for implementation simplicity via shallow subtyping schemes. It suggests extending type checking pipelines to include an automated eta-expansion phase, simplifying subsequent type checks and reasoning processes while maintaining deeper type structure expressiveness.

Conclusion

The paper provides a structured approach to managing the complexity in type systems facilitated through eta-expansion, alleviating the burden of deep subtyping reasoning while preserving necessary expressiveness. This allows developers to design systems with comprehensible subtyping mechanisms, balancing practical efficiency against theoretical depth for functional programming languages, increasing the tractability of complex type systems through practical, automated expansions.

Ai Generate Text Spark Streamline Icon: https://streamlinehq.com

Paper Prompts

Sign up for free to create and run prompts on this paper using GPT-5.

Authors (1)

X Twitter Logo Streamline Icon: https://streamlinehq.com