forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Context Bounds for Polymorphic Functions (scala#21643)
Implement the `scala#6` point form SIP-64 i.e. --- ### 6. Context Bounds for Polymorphic Functions Currently, context bounds can be used in methods, but not in function types or function literals. It would be nice propose to drop this irregularity and allow context bounds also in these places. Example: ```scala type Comparer = [X: Ord] => (x: X, y: X) => Boolean val less: Comparer = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0 ``` The expansion of such context bounds is analogous to the expansion in method types, except that instead of adding a using clause in a method, we insert a context function type. For instance, the `type` and `val` definitions above would expand to ```scala type Comparer = [X] => (x: X, y: X) => Ord[X] ?=> Boolean val less: Comparer = [X] => (x: X, y: X) => (ord: Ord[X]) ?=> ord.compare(x, y) < 0 ``` The expansion of using clauses does look inside alias types. For instance, here is a variation of the previous example that uses a parameterized type alias: ```scala type Cmp[X] = (x: X, y: X) => Boolean type Comparer2 = [X: Ord] => Cmp[X] ``` The expansion of the right hand side of `Comparer2` expands the `Cmp[X]` alias and then inserts the context function at the same place as what's done for `Comparer`.
- Loading branch information
Showing
6 changed files
with
274 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.