File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments