Type inference for polymorphic methods in Java-like languages

D. Ancona, Giovanni Lagorio, E. Zucca
{"title":"Type inference for polymorphic methods in Java-like languages","authors":"D. Ancona, Giovanni Lagorio, E. Zucca","doi":"10.1142/9789812770998_0014","DOIUrl":null,"url":null,"abstract":"In mainstream class-based object-oriented languages with nominal types, like C++, Java and C#, typechecking algorithms require methods to be annotated with their parameter types, which are either fixed or constrained by a (nominal) bound. On the contrary, languages like ML, CaML and Haskell use powerful type inference algorithms capable of calculating the type for a function in which parameter types are left unspecified. This inferred type is possibly polymorphic, hence functions can be applied to arguments of different, unrelated, types, which are instances of the same schema. We show that, surprisingly enough, the latter scenario works smoothly for Java-like languages too. That is, we can define polymorphic types for methods and automatically infer these types when type annotations are omitted. These polymorphic types intuitively capture the (less restrictive) requirements on arguments needed to safely apply the method. Moreover, the approach enjoys separate compilation a la Java. We formalize our ideas on a minimal Java subset, for which we define a type system with polymorphic types and prove its soundness. We then describe an algorithm for type inference and prove its soundness and completeness. A prototype implementing inference of polymorphic types from untyped code is available.","PeriodicalId":212849,"journal":{"name":"Italian Conference on Theoretical Computer Science","volume":"115 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2007-09-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"12","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Italian Conference on Theoretical Computer Science","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1142/9789812770998_0014","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 12

Abstract

In mainstream class-based object-oriented languages with nominal types, like C++, Java and C#, typechecking algorithms require methods to be annotated with their parameter types, which are either fixed or constrained by a (nominal) bound. On the contrary, languages like ML, CaML and Haskell use powerful type inference algorithms capable of calculating the type for a function in which parameter types are left unspecified. This inferred type is possibly polymorphic, hence functions can be applied to arguments of different, unrelated, types, which are instances of the same schema. We show that, surprisingly enough, the latter scenario works smoothly for Java-like languages too. That is, we can define polymorphic types for methods and automatically infer these types when type annotations are omitted. These polymorphic types intuitively capture the (less restrictive) requirements on arguments needed to safely apply the method. Moreover, the approach enjoys separate compilation a la Java. We formalize our ideas on a minimal Java subset, for which we define a type system with polymorphic types and prove its soundness. We then describe an algorithm for type inference and prove its soundness and completeness. A prototype implementing inference of polymorphic types from untyped code is available.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
类java语言中多态方法的类型推断
在具有名义类型的主流基于类的面向对象语言中,如c++、Java和c#,类型检查算法要求用参数类型对方法进行注释,这些参数类型要么是固定的,要么受到(名义)界限的约束。相反,像ML、CaML和Haskell这样的语言使用强大的类型推断算法,能够计算未指定参数类型的函数的类型。这种推断的类型可能是多态的,因此函数可以应用于不同的、不相关的类型的参数,这些类型是同一模式的实例。令人惊讶的是,我们展示了后一种场景对于类java语言也能顺利地工作。也就是说,我们可以为方法定义多态类型,并在省略类型注释时自动推断出这些类型。这些多态类型直观地捕获了安全应用该方法所需的参数需求(限制较少)。此外,这种方法可以像Java那样独立编译。我们在一个最小的Java子集上形式化了我们的想法,为此我们定义了一个具有多态类型的类型系统,并证明了它的可靠性。然后,我们描述了一种类型推理算法,并证明了它的正确性和完备性。实现从非类型化代码推断多态类型的原型是可用的。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
Uniform Circle Formation for Fully Semi-, and Asynchronous Opaque Robots with Lights On the Parametrized Complexity of the s-Club Cluster Edge Deletion Problem On the Domination Number of t-Constrained de Bruijn Graphs Tracing and Preventing Sharing and Mutation System Analysis and Robustness
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1