The type checking happens in two steps:
Suppose a function f
of the form (p1, ..., pn) => e
(where n > 1
), with p1, ..., pn
as parameters and e
as function body.
If the expected type for checking f
is a fully defined function type of the form TupleN[T1, ..., Tn] => R
(or an equivalent SAM-type), where each type Ti
fits the corresponding parameter pi
. Then f
is feasible for parameter untupling with the expected type TupleN[T1, ..., Tn] => R
.
A type Ti
fits a parameter pi
if one of the following two cases is true
:
pi
comes without a type, i.e. it is a simple identifier or _
.pi
is of the form x: Ui
or _: Ui
and Ti <: Ui
.Parameter untupling composes with eta-expansion. That is, an n-ary function generated by eta-expansion can in turn be adapted to the expected type with parameter untupling.
Term adaptationIf the function
is feasible for parameter untupling with the expected type TupleN[T1, ..., Tn] => Te
, then continue to type check the following adapted function
(x: TupleN[T1, ..., Tn]) =>
def p1: T1 = x._1
...
def pn: Tn = x._n
e
with the same expected type.
MigrationCode like this could not be written before, hence the new notation is not ambiguous after adoption.
It is possible that someone has written an implicit conversion from (T1, ..., Tn) => R
to TupleN[T1, ..., Tn] => R
for some n
. Such a conversion is now only useful for general conversions of function values, when parameter untupling is not applicable. Some care is required to implement the conversion efficiently. Obsolete conversions could be detected and fixed by Scalafix
.
For more information, see Issue #897.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4