Variant parametric types: A flexible subtyping scheme for generics

被引:31
|
作者
Igarashi, Atsushi [1 ]
Viroli, Mirko
机构
[1] Kyoto Univ, Grad Sch Informat, Sakyo Ku, Kyoto 6068501, Japan
[2] Univ Bologna, DEIS, Alma Mater Studiorum, I-47023 Cesena, FC, Italy
关键词
generic classes; !text type='Java']Java[!/text; language design; language semantics; subtyping; variance;
D O I
10.1145/1152649.1152650
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
We develop the mechanism of variant parametric types as a means to enhance synergy between parametric and inclusion polymorphism in object-oriented programming languages. Variant parametric types are used to control both the subtyping between different instantiations of one generic class and the accessibility of their fields and methods. On one hand, one parametric class can be used to derive covariant types, contravariant types, and bivariant types ( generally called variant parametric types) by attaching a variance annotation to a type argument. On the other hand, the type system prohibits certain method/field accesses, according to variance annotations, when these accesses may otherwise make the program unsafe. By exploiting variant parametric types, a programmer can write generic code abstractions that work on a wide range of parametric types in a safe manner. For instance, a method that only reads the elements of a container of numbers can be easily modified so as to accept containers of integers, floating-point numbers, or any subtype of the number type. Technical subtleties in typing for the proposed mechanism are addressed in terms of an intuitive correspondence between variant parametric and bounded existential types. Then, for a rigorous argument of correctness of the proposed typing rules, we extend Featherweight GJ-an existing formal core calculus for Java with generics-with variant parametric types and prove type soundness.
引用
收藏
页码:795 / 847
页数:53
相关论文
共 50 条
  • [1] A Subtyping Scheme for Nominal and Structural Types Based on Class Graph Equivalence
    Ke, Wei
    Chan, Ka-Hou
    [J]. 2021 4TH INTERNATIONAL CONFERENCE ON BLOCKCHAIN TECHNOLOGY AND APPLICATIONS, ICBTA 2021, 2021, : 151 - 157
  • [2] Parametric Subtyping for Structural Parametric Polymorphism
    DeYoung, Henry
    Mordido, Andreia
    Pfenning, Frank
    Das, Ankush
    [J]. PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2024, 8 (POPL):
  • [3] An Interval-Based Inference of Variant Parametric Types
    Craciun, Florin
    Chin, Wei-Ngan
    He, Guanhua
    Qin, Shengchao
    [J]. PROGRAMMING LANGUAGES AND SYSTEMS, PROCEEDINGS, 2009, 5502 : 112 - +
  • [4] A flow-based approach for variant parametric types
    Chin, Wei-Ngan
    Craciun, Florin
    Khoo, Siau-Cheng
    Popeea, Corneliu
    [J]. ACM SIGPLAN NOTICES, 2006, 41 (10) : 273 - 290
  • [5] Subtyping union types
    Vouillon, R
    [J]. COMPUTER SCIENCE LOGIC, PROCEEDINGS, 2004, 3210 : 415 - 429
  • [6] Subtyping dependent types
    Aspinall, D
    Compagnoni, A
    [J]. 11TH ANNUAL IEEE SYMPOSIUM ON LOGIC IN COMPUTER SCIENCE, PROCEEDINGS, 1996, : 86 - 97
  • [7] SUBTYPING RECURSIVE TYPES
    AMADIO, RM
    CARDELLI, L
    [J]. ACM TRANSACTIONS ON PROGRAMMING LANGUAGES AND SYSTEMS, 1993, 15 (04): : 575 - 631
  • [8] Phantom types and subtyping
    Fluet, Matthew
    Pucella, Riccardo
    [J]. IFIP Advances in Information and Communication Technology, 2002, 96 : 448 - 460
  • [9] Subtyping dependent types
    Aspinall, D
    Compagnoni, A
    [J]. THEORETICAL COMPUTER SCIENCE, 2001, 266 (1-2) : 273 - 309
  • [10] Phantom types and subtyping
    Fluet, M
    Pucella, R
    [J]. FOUNDATIONS OF INFORMATION TECHNOLOGY IN THE ERA OF NETWORK AND MOBILE COMPUTING, 2002, 96 : 448 - 460