File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
docs/docs/reference/new-types Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ Match types can form part of recursive type definitions. Example:
3434 case String => Char
3535 case Array [t] => LeafElem [t]
3636 case Iterable [t] => LeafElem [t]
37- case t <: AnyVal => t
37+ case AnyVal => X
3838 }
3939```
4040Recursive match type definitions can also be given an upper bound, like this:
Original file line number Diff line number Diff line change 1+ object Test {
2+
3+ type LeafElem [X ] = X match {
4+ case String => Char
5+ case Array [t] => LeafElem [t]
6+ case Iterable [t] => LeafElem [t]
7+ case AnyVal => X
8+ }
9+
10+ the[LeafElem [String ] =:= Char ]
11+ the[LeafElem [Array [Int ]] =:= Int ]
12+ the[LeafElem [Iterable [Int ]] =:= Int ]
13+ the[LeafElem [Int ] =:= Int ]
14+ }
Original file line number Diff line number Diff line change 1+ object Test {
2+
3+ type AV [t <: AnyVal ] = t
4+
5+ type LeafElem [X ] = X match {
6+ case String => Char
7+ case Array [t] => LeafElem [t]
8+ case Iterable [t] => LeafElem [t]
9+ case AV [t] => t
10+ }
11+
12+ the[LeafElem [String ] =:= Char ]
13+ the[LeafElem [Array [Int ]] =:= Int ]
14+ the[LeafElem [Iterable [Int ]] =:= Int ]
15+ the[LeafElem [Int ] =:= Int ]
16+ }
You can’t perform that action at this time.
0 commit comments