There is something still not right with givens after the Given without as rework, which I think is important to address prior to RC1 as it is interfering in the discussion on optional braces.
What triggered the rework was the relevant remark that as
makes better sense as Type as value
rather than value as Type
as was the case in givens. It is a good remark.
However, what comes after as
in givens in some cases is not a type (nor a value) but a constructor. Formerly it was the implicit class case. Now it called structural instance:
given intOrd: Ord[Int] with
...
The other forms of givens are given alias:
given global: ExecutionContext = ForkJoinPool()
and (introduced by the PR above) abstract given:
given global: ExecutionContext
In these two cases colon (:
) makes perfect sense in replacement of as
as it is followed by a type. But in the structural instance case we have a constructor. What happens if we have no structural part to define:
given intOrd: MyConcreteOrd
, is that in order to disambiguate w.r.t. an abstract given we must append with
+ an empty body:
given intOrd: MyConcreteOrd with {}
There are several problems with this.
- it is not pretty
- it is verbose
- it forces us to use
with
whereas colon (:
) would be more appropriate to start an indented body. - it does not work without braces:
given intOrd: MyConcreteOrd with
<nothing>
or
given intOrd: MyConcreteOrd:
<nothing>
-> don’t work.
5) class declarations don’t have this constraint:
class intOrd extends MyConcreteOrd
So the question is : how do we disambiguate from abstract given without with
? One answer would be to bring back as
in the structural instance case (only). One other possibility would be extends
:
given intOrd extends Ord[Int]:
...
given intOrd extends MyConcreteOrd
Anonymous would be unchanged:
given Ord[Int]:
...
Given alias could be replaced by this more compact form if desired:
given ForkJoinPool
Reactions?