A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.scala-lang.org/scala3/reference/other-new-features/parameter-untupling-spec.html below:

Parameter Untupling - More Details

Edit this page on GitHub Parameter Untupling - More Details Type Checking

The type checking happens in two steps:

  1. Check whether parameter untupling is feasible
  2. Adapt the function and type check it
Feasibility Check

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:

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 adaptation

If 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.

Migration

Code 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.

Reference

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