Skip to main content
QUICK REVIEW

[论文解读] Java & Lambda: a Featherweight Story

Lorenzo Bettini, Viviana Bono|arXiv (Cornell University)|Jan 15, 2018
Logic, programming, and type systems参考文献 2被引用 4
一句话总结

本文提出 FJλ,一种形式化核心演算,扩展了 Featherweight Java,支持接口、多重继承、lambda 表达式以及交集类型。通过证明主体约化和进展性,建立了类型安全性,展示了 Java 8 中的 lambda 和交集类型特性在一种最小化、类型安全的模型中的形式化基础。

ABSTRACT

We present FJ&$\lambda$, a new core calculus that extends Featherweight Java (FJ) with interfaces, supporting multiple inheritance in a restricted form, $\lambda$-expressions, and intersection types. Our main goal is to formalise how lambdas and intersection types are grafted on Java 8, by studying their properties in a formal setting. We show how intersection types play a significant role in several cases, in particular in the typecast of a $\lambda$-expression and in the typing of conditional expressions. We also embody interface \emph{default methods} in FJ&$\lambda$, since they increase the dynamism of $\lambda$-expressions, by allowing these methods to be called on $\lambda$-expressions. The crucial point in Java 8 and in our calculus is that $\lambda$-expressions can have various types according to the context requirements (target types): indeed, Java code does not compile when $\lambda$-expressions come without target types. In particular, in the operational semantics we must record target types by decorating $\lambda$-expressions, otherwise they would be lost in the runtime expressions. We prove the subject reduction property and progress for the resulting calculus, and we give a type inference algorithm that returns the type of a given program if it is well typed. The design of FJ&$\lambda$ has been driven by the aim of making it a subset of Java 8, while preserving the elegance and compactness of FJ. Indeed, FJ&$\lambda$ programs are typed and behave the same as Java programs.

研究动机与目标

  • 正式建模 Java 8 中将 lambda 表达式与交集类型集成到一个最小化核心演算中的机制。
  • 解决 lambda 表达式中上下文依赖类型带来的挑战,其中目标类型对于类型推断和运行时行为至关重要。
  • 在扩展现代 Java 8 特性的同时,保持 Featherweight Java 的优雅性与类型安全性。
  • 证明所得到的演算 FJλ 保持主体约化与进展性,确保类型安全性。
  • 探讨交集类型在类型转换、条件表达式以及对 lambda 表达式的方法调用中的作用。

提出的方法

  • 扩展 Featherweight Java (FJ),支持受限的多重继承和默认方法的接口。
  • 引入带有目标类型的 lambda 表达式,并在运行时通过装饰机制保留上下文依赖类型。
  • 使用 & 符号表示交集类型,仅对交集类型应用结构子类型规则。
  • 定义一种双向类型系统,结合标准类型检查与 lambda 的类型推断,使用目标类型作为上下文约束。
  • 引入一种类型推断算法,从类表和项中推导程序的类型。
  • 证明该演算的主体约化与进展性,确保在操作语义下的类型安全性。

实验结果

研究问题

  • RQ1如何在具有上下文依赖类型的核心演算中,形式化 Java 8 中的 lambda 表达式?
  • RQ2交集类型在支持 lambda 的多个函数式接口类型以及条件表达式中的作用是什么?
  • RQ3如何在操作语义中保留目标类型以确保类型安全性?
  • RQ4接口中的默认方法如何增强演算中 lambda 表达式的动态性?
  • RQ5在结合面向对象与函数式特性的演算中,可以证明哪些形式化保证(例如主体约化、进展性)?

主要发现

  • FJλ 在保持主体约化与进展性的同时,成功扩展了 Featherweight Java,支持 lambda 表达式与交集类型。
  • 该演算证明了 Java 8 的 lambda 与交集类型特性在形式化上是类型安全的,由主体约化与进展定理所支持。
  • 交集类型在类型化条件表达式以及将 lambda 表达式转换为多个函数式接口类型时至关重要。
  • lambda 表达式中使用目标类型得到了形式化证明,因为缺少目标类型将导致类型错误,且必须通过装饰机制在运行时保留。
  • 该演算引入了一种新颖的子类型规则 [<: &L] 用于交集类型,据作者所知,此前在该上下文中尚未对此进行过形式化。
  • 形式化表明,泛型类型与函数式接口交集带来了重大挑战,提示未来工作应扩展 FJ&lambda; 以支持泛型。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。