HaxeDoc2

(やまだぃちぅ) #1
7 }

8
9 static function add(i1:Int, i2:Int){
10 return i1 + i2;
11 }
12
13 static function mul(i1:Int, i2:Int){
14 return i1 * i2;
15 }
16 }
This traces 12 as a result of the calls toadd(3, 1), where 3 is the matched value, and
mul(4, 3)where 4 is the result of theaddcall. It is worth noting that theaon the right side of
the second=>operator is a capture variable (6.4.3).
It is currently not possible to use extractors within or-patterns (6.4.6):
1 class Main {
2 static public function main() {
3 switch("foo"){
4 // Extractors in or patternsare not
5 // allowed
6 case (_.toLowerCase() => "foo")|"bar":
7 }
8 }
9 }
However, it is possible to have or-patterns on the right side of an extractor, so the previous
example would compile without the parentheses.

6.4.10 Exhaustiveness checks


The compiler ensures that no possible cases are forgotten:
1 switch(true){
2 case false:
3 } // Unmatched patterns: true
The matched typeBooladmits two valuestrueandfalse, but onlyfalseis checked.
Figure out wtf our
rules are now for
when this is checked.


Figure out wtf our
rules are now for


6.4.11 Useless pattern checks


In a similar fashion, the compiler detects patterns which will never match the input value:
1 switch(Leaf("foo")) {
2 case Leaf(_)
3 | Leaf("foo"): // This patternis unused
4 case Node(l,r):
5 case _: // This pattern is unused
6 }
Free download pdf