Skip to content

Commit 7791243

Browse files
committed
Start unused parameters user documentation
1 parent 12cdd19 commit 7791243

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

docs/docs/reference/unused-terms.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
layout: doc-page
3+
title: "Unused Parameters"
4+
---
5+
6+
Why unused parameters?
7+
----------------------
8+
TODO
9+
10+
11+
What are unused parameter?
12+
--------------------------
13+
Unused parameter are values that are know not to be used. Parameters of methods and functions
14+
can be declared as unused. Those parameters wont be usable for computations, thought they can
15+
be used as arguments to other unused parameters.
16+
17+
```scala
18+
def methodWithUnusedEv(unused ev: Ev): Int = 42
19+
20+
val lambdaWithUnusedEv: unused Ev => Int =
21+
unused (ev: Ev) => 42
22+
```
23+
24+
Not only parameters can be marked as unused, `val` and `def` can also be marked with `unused`.
25+
The will also only be usable as arguments to `unused` parameters.
26+
27+
```scala
28+
unused val unusedEvidence: Ev = ...
29+
methodWithUnusedEv(unusedEvidence)
30+
```
31+
32+
33+
What happens with unused values at runtime?
34+
-------------------------------------------
35+
As `unused` are guaranteed not to be used in computations, they can and will be erased.
36+
37+
```scala
38+
// becomes def methodWithUnusedEv(): Int at runtime
39+
def methodWithUnusedEv(unused ev: Ev): Int = ...
40+
41+
def evidence1: Ev = ...
42+
unused def unusedEvidence2: Ev = ... // does not exist at runtime
43+
unused val unusedEvidence3: Ev = ... // does not exist at runtime
44+
45+
// evidence1 is evaluated but the result is not passed to methodWithUnusedEv
46+
methodWithUnusedEv(evidence1)
47+
48+
// unusedEvidence2 is not evaluated and its result is not passed to methodWithUnusedEv
49+
methodWithUnusedEv(unusedEvidence2)
50+
```
51+
52+
Examples
53+
--------
54+
TODO
55+
56+
```scala
57+
58+
```

0 commit comments

Comments
 (0)