From ed988fdacf4fb1e54927965291eb4b93bf4a45e2 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 15 Apr 2024 15:45:16 +0200 Subject: [PATCH] Motivation: comparision to local type inference --- introduction.tex | 35 +++++++++++++++++++++++++++++++++++ martin.bib | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/introduction.tex b/introduction.tex index f3d9515..85a7ba0 100644 --- a/introduction.tex +++ b/introduction.tex @@ -19,6 +19,41 @@ class Test { } \end{verbatim} +TypeError: +\begin{verbatim} +void test(){ + var l = new ArrayList(); + l.add("hi"); + var s = l.stream().map(i -> 1).collect(Collectors.toList()); + var s2 = l.stream().map(i -> "String").collect(Collectors.toList()); + receive(s, s2); + } + void receive(List l, List l2){} +\end{verbatim} +Correct: +\begin{verbatim} +void test(){ + var l = new ArrayList(); + l.add("hi"); + List s = l.stream().map(i -> 1).collect(Collectors.toList()); + List s2 = l.stream().map(i -> "String").collect(Collectors.toList()); + receive(s, s2); + } + void receive(List l, List l2){} +\end{verbatim} + +The big difference to local type inference is the ability to have constraints where both sides contain type placeholders. +As described in \cite{javaTIisBroken} local type inference is able to determine an unifier $\sigma$ +which satisfies $\set{\overline{A <: \sigma(F)}, \sigma(R) <: E }$. +Note that $A$ and $E$ are already given types. +$A$ are method arguments and $E$ is the expected return type. + +% Are there examples where the expected return type is not given? +% with global type inference this is easy to produce +% an example where this is the case for local type inference? +% - the val example +% - + \section{Type Inference for Java} %The goal is to find a correct typing for a given Java program. Type inference for Java has many use cases and could be used to help programmers by inserting correct types for them, diff --git a/martin.bib b/martin.bib index 4e34d05..64db956 100644 --- a/martin.bib +++ b/martin.bib @@ -433,7 +433,7 @@ numpages = {14}, keywords = {existential types, joins, parametric types, single-instantiation inheritance, subtyping, type inference, wildcards} } -@inproceedings{10.1145/1449764.1449804, +@inproceedings{javaTIisBroken, author = {Smith, Daniel and Cartwright, Robert}, title = {Java type inference is broken: can we fix it?}, year = {2008},