- 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, int types are considered subtypes of rat 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=′paper−heading′id=′lemma−and−theorem−of−eta−expansion′>LemmaandTheoremofEtaExpansion</h3><p>Thecriticalcontributionliesinaformalproofthateta−expansionmaintainsthecompletenessofatypesystemwithdeepsubtypingwhentransitioningtoashallowsubtypingsystem.Thetechnicallemmashowsthatshallowsystemscanprocessdeepsubtypingcorrectlywhentermsareappropriatelyeta−expanded.</p><p><strong>Lemma−ShallowExpansion</strong>:</p><p>IfatypeAisadeepsubtypeofBandatermehastypeA,thenthereexistsaneta−expandedterme'suchthate'isconvertibletoeandisvalidundertypeB$ 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.