You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/typeclasses-syntax.md
+27-1Lines changed: 27 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,7 +194,27 @@ The using clause in class `SortedSet` provides an implementation for the deferre
194
194
**Alternative:** It was suggested that we use a modifier for a deferred given instead of a `= deferred`. Something like `deferred given C[T]`. But a modifier does not suggest the concept that a deferred given will be implemented automatically in subclasses unless an explicit definition is written. In a sense, we can see `= deferred` as the invocation of a magic macro that is provided by the compiler. So from a user's point of view a given with `deferred` right hand side is not abstract.
195
195
It is a concrete definition where the compiler will provide the correct implementation.
196
196
197
-
### 5. Cleanup of Given Syntax
197
+
### 5. Context Bounds for Polymorphic Functions
198
+
199
+
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:
200
+
201
+
```scala
202
+
typeComparer= [X:Ord] => (x: X, y: X) =>Boolean
203
+
valless:Comparer= [X:Ordasord] => (x: X, y: X) =>
204
+
ord.compare(x, y) <0
205
+
```
206
+
207
+
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.
A good language syntax is like a Bach fugue: A small set of motifs is combined in a multitude of harmonic ways. Dissonances and irregularities should be avoided.
The syntax for function types `FunType` and function expressions `FunExpr` also gets simpler. We can now use a regular `DefTypeParamClause` that is also used for `def` definitions and allow context bounds in type parameters.
0 commit comments