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
This is a trial balloon to see whether `forms` works better than `this`.
My immediate reaction is meh. Sometimes it's OK, at other times I liked `is` better.
But I admit there's bias since the examples were chosen to work well with `is`.
Copy file name to clipboardExpand all lines: docs/_docs/reference/experimental/typeclasses.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,11 +134,11 @@ We introduce a standard type alias `is` in the Scala package or in `Predef`, def
134
134
This makes writing instance definitions quite pleasant. Examples:
135
135
136
136
```scala
137
-
givenIntisOrd ...
138
-
givenIntisMonoid ...
137
+
givenIntformsOrd ...
138
+
givenIntformsMonoid ...
139
139
140
140
typeReader= [X] =>>Env=>X
141
-
givenReaderisMonad ...
141
+
givenReaderformsMonad ...
142
142
```
143
143
144
144
(more examples will follow below)
@@ -149,7 +149,7 @@ This makes writing instance definitions quite pleasant. Examples:
149
149
150
150
Context bounds are a convenient and legible abbreviation. A problem so far is that they are always anonymous, one cannot name the using parameter to which a context bound expands. For instance, without the trick of defining a universal "trampoline" `unit` in the `Monoid` companion object, we would have to write `reduce` like this:
151
151
```scala
152
-
defreduce[A](xs: List[A])(usingm: AisMonoid) =
152
+
defreduce[A](xs: List[A])(usingm: AformsMonoid) =
153
153
xs.foldLeft(m.unit)(_ `combine` _)
154
154
```
155
155
@@ -197,7 +197,7 @@ Context bounds are currently translated to implicit parameters in the last param
But this is ill-typed, since the `C` in `C.input` refers to the `C` introduced in the using clause, which comes later.
203
203
@@ -254,7 +254,7 @@ type T: C
254
254
in a trait will then expand to
255
255
```scala
256
256
typeT
257
-
givenTisC= deferred
257
+
givenTformsC= deferred
258
258
```
259
259
260
260
@@ -281,14 +281,14 @@ The awkwardness of the given syntax was forced upon us since we insisted that gi
281
281
and we can use a more intuitive syntax for givens like this:
282
282
283
283
```scala
284
-
givenIntisOrd:
284
+
givenIntformsOrd:
285
285
defcompare(x: A, y: A) = ...
286
286
287
-
given [A:Ord] =>List[A] isOrd:
287
+
given [A:Ord] =>List[A] formsOrd:
288
288
defcompare(x: A, y: A) =
289
289
...
290
290
291
-
givenIntisMonoidasintMonoid:
291
+
givenIntformsMonoidasintMonoid:
292
292
extension (x: Int) defcombine(y: Int) = x + y
293
293
defunit=0
294
294
```
@@ -303,7 +303,7 @@ The underlying principles are:
303
303
- an implementation which consists of either an `=` and an expression,
304
304
or a template body.
305
305
306
-
- We get the pleasing `<instance-type> is <type-class>` syntax simply by using the predefined infix type `is`.
306
+
- We get the pleasing `<instance-type> forms <type-class>` syntax simply by using the predefined infix type `forms`.
307
307
- Since there is no more middle `:` separating name and parameters from the implemented type, we can use a `:` to start the class body without looking unnatural. That eliminates the special case where `with` was used before.
308
308
309
309
This will be a fairly significant change to the given syntax. I believe there's still a possibility to do this,
@@ -326,7 +326,7 @@ This is less of a disruption than it might appear at first:
326
326
-`given T` was illegal before since abstract givens could not be anonymous.
327
327
It now means a concrete given of class `T` with no member definitions. This
328
328
is the natural interpretation for simple tagging given clauses such as
329
-
`given String is Value`.
329
+
`given String forms Value`.
330
330
-`given x: T` is legacy syntax for a deferred given.
331
331
-`given T as x = deferred` is the analogous new syntax, which is more powerful since
332
332
it allows for automatic instantiation.
@@ -396,14 +396,14 @@ Here are some standard type classes, which were mostly already introduced at the
defmap[B](x: EmptyTuple)(f: Nothing=>B):Mapped[B] = x
489
489
490
-
given [A, Rest<:Tuple:TupleOf[A]] =>A*:RestisTupleOf[A]:
490
+
given [A, Rest<:Tuple:TupleOf[A]] =>A*:RestformsTupleOf[A]:
491
491
typeMapped[+A] =A*:Rest.Mapped[A]
492
492
defmap[B](x: A*:Rest)(f: A=>B):Mapped[B] =
493
493
f(x.head) *:Rest.map(x.tail)(f)
@@ -532,14 +532,14 @@ end Combinator
532
532
caseclassApply[I, R](action: I=>Option[R])
533
533
caseclassCombine[A, B](a: A, b: B)
534
534
535
-
given [I, R] =>Apply[I, R] isCombinator:
535
+
given [I, R] =>Apply[I, R] formsCombinator:
536
536
typeInput=I
537
537
typeResult=R
538
538
extension (self: Apply[I, R])
539
539
defparse(in: I):Option[R] = self.action(in)
540
540
541
541
given [A:Combinator, B:Combinator { typeInput=A.Input }]
542
-
=>Combine[A, B] isCombinator:
542
+
=>Combine[A, B] formsCombinator:
543
543
typeInput=A.Input
544
544
typeResult= (A.Result, B.Result)
545
545
extension (self: Combine[A, B])
@@ -567,7 +567,7 @@ to take the original example and show how it can be made to work with the new co
567
567
_Note 2:_ One could improve the notation even further by adding equality constraints in the style of Swift, which in turn resemble the _sharing constraints_ of SML. A hypothetical syntax applied to the second given would be:
568
568
```scala
569
569
given [A:Combinator, B:CombinatorwithA.Input==B.Input]
570
-
=>Combine[A, B] isCombinator:
570
+
=>Combine[A, B] formsCombinator:
571
571
```
572
572
This variant is aesthetically pleasing since it makes the equality constraint symmetric. The original version had to use an asymmetric refinement on the second type parameter bound instead. For now, such constraints are neither implemented nor proposed. This is left as a possibility for future work. Note also the analogy with
573
573
the work of @mbovel and @Sporarum on refinement types, where similar `with` clauses can appear for term parameters. If that work goes ahead, we could possibly revisit the issue of `with` clauses also for type parameters.
0 commit comments