Skip to content

Commit 86f24d2

Browse files
committed
Add section on unused
1 parent bf77e84 commit 86f24d2

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

docs/blog/_posts/2018-03-05-seventh-dotty-milestone-release.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,29 @@ object Option {
7171
You can visit our website for more information about [enumerations](/docs/reference/enums/enums.html)
7272
and how we can use them to model [Algebraic Data Types](/docs/reference/enums/adts.html).
7373

74-
### Unused Parameters [#3342](https://github.com/lampepfl/dotty/pull/3342)
75-
TODO
74+
### Unused Parameters [#3342](https://github.com/lampepfl/dotty/pull/3342) and remove Phantom types [#3410](https://github.com/lampepfl/dotty/pull/3410)
75+
The keyword `unsued` can be placed on parameters, `val` and `def` to enforce that no reference to
76+
those terms is ever used (recursively). As they are never used, they can safely be removed during compilation.
77+
These have similar semantics as _phantom types_ but with the added advantage that any type can be an unused parameter. They can be used to add implicit type constraints that are only relevant at compilation time.
78+
79+
```scala
80+
// A function that requires an implicit evidence of type X =:= Y but never uses it.
81+
// The parameter will be removed and the argument will not be evaluated.
82+
def apply(implicit unused ev: X =:= Y) =
83+
foo(ev) // `ev` can be an argument to foo as foo will also never use it
84+
def foo(unused x: X =:= Y) = ()
85+
```
86+
87+
The previous code will be transformed to the following:
88+
89+
```scala
90+
def apply() = // unused parameter will be removed
91+
foo() // foo is called without the unused parameter
92+
def foo() = () // unused parameter will be removed
93+
```
94+
95+
[Documentation](/docs/reference/unused-parameters.html)
96+
7697

7798
## Trying out Dotty
7899
### Scastie

0 commit comments

Comments
 (0)