{"title":"类java语言中多态方法的类型推断","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":"{\"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}","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}
Type inference for polymorphic methods in Java-like languages
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.