paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Covariance and Controvariance: a fresh look at an old issue (a primer in advanced type systems for learning functional programmers)

协变与逆变:对一个老问题的新审视(供函数式程序员学习的进阶类型系统入门)
LMCS vol.Volume 16, Issue 12022匹配度 3/10 · 论文属于类型系统与语言设计的理论基础,虽与程序语言方向相关,但未涉及用户核心关注的静态分析、LLM/Agent、浮点程序分析或贝叶斯程序分析。引用 6 inbox
Giuseppe Castagna
crossref: 2026-09-10

AI 速览

一句话:重新审视面向对象方法参数的协变/逆变特化,论证二者可在同一语言中共存,并以实例讲解进阶类型系统概念与实现技巧。

本文重新审视作者二十年前关于协变与逆变特化的文章。该文曾指出,面向对象编程中方法参数的协变与逆变特化目的不同,因此不仅能够、而且应当在同一语言中共存。作者结合子类型理论及编程语言的最新进展,对这一旧问题给出新视角;但文章更主要的目的是以简单术语和示例,向本科生及愿意学习的函数式程序员解释复杂的类型论概念。文章还借此机会描述了一些鲜为人知的类型系统实现高级技术,这些技术原先只见于少数深入编译器源码的内行。因而,即使资深语言设计者和实现者也可能从中获益。

问题
在子类型与面向对象方法特化中,协变和逆变长期被视为冲突;本文重新审视二者能否以及为何应在同一语言中共存,并降低进阶类型系统概念的学习门槛。
方法
以作者旧文为线索,结合子类型理论的新进展,采用示例驱动的随笔/入门式论述;同时披露若干类型系统实现的高级技巧。
评估
本文为概念性与教学性文章,不报告实证评估;通过示例和理论讨论说明观点,并给出修正版内容。
原文摘要(Abstract)

Twenty years ago, in an article titled "Covariance and contravariance: conflict without a cause", I argued that covariant and contravariant specialization of method parameters in object-oriented programming had different purposes and deduced that, not only they could, but actually they should both coexist in the same language. In this work I reexamine the result of that article in the light of recent advances in (sub-)typing theory and programming languages, taking a fresh look at this old issue. Actually, the revamping of this problem is just an excuse for writing an essay that aims at explaining sophisticated type-theoretic concepts, in simple terms and by examples, to undergraduate computer science students and/or willing functional programmers. Finally, I took advantage of this opportunity to describe some undocumented advanced techniques of type-systems implementation that are known only to few insiders that dug in the code of some compilers: therefore, even expert language designers and implementers may find this work worth of reading.Comment: This is a corrected version of the paper arXiv:1809.01427v7 published originally on Feb. 13, 2020

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot1722,
  title = {Covariance and Controvariance: a fresh look at an old issue (a primer in advanced type systems for learning functional programmers)},
  author = {Giuseppe Castagna},
  journal = {Logical Methods in Computer Science},
  volume = {Volume 16, Issue 1},
  year = {2022},
  doi = {10.23638/lmcs-16(1:15)2020}
}