Skip to content

Commit 9b50458

Browse files
committed
Describe updates to match syntax from PR #242
1 parent ec41c2c commit 9b50458

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

docs/simplicityhl-reference/match_expression.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,17 @@ let map_either: u32 = match Left(1337) {
5858
};
5959
```
6060

61-
Match expressions don't support further pattern matching, in contrast to Rust.
61+
Since SimplicityHL 0.5.0, the match expression also supports further pattern matching, similar to Rust.
6262

6363
```rust
6464
let unwrap_or_default: u32 = match Some((4, 2)) {
6565
None => 0,
66-
// this doesn't compile
6766
Some((y, z): (u16, u16)) => <(u16, u16)>::into((y, z)),
6867
};
6968
```
7069

71-
However, the match arm can contain code that performs the deconstruction.
72-
For example, the tuple `x` of type `(u16, u16)` can be deconstructed into two integers `y` and `z` of type `u16`.
70+
This is more concise than including code to perform the deconstruction inside the match arm.
71+
For example, the code above is a more concise alternative to this version that subsequently deconstructes the tuple `x` of type `(u16, u16)` into two integers `y` and `z` of type `u16`.
7372

7473
```rust
7574
let unwrap_or_default: u32 = match Some((4, 2)) {
@@ -93,3 +92,9 @@ let unwrap_or_default: u32 = match Some(Left(42)) {
9392
},
9493
};
9594
```
95+
96+
## Only two branches per `match`
97+
98+
Differently from Rust, the `match` expression only allows two match arms (branches) per `match`.
99+
For example, it is currently not possible to match `Left(Left(x: u8))`, `Left(Right(x: u8)`, `Right(Left(x: u8))`, and `Right(Right(x: u8))` as arms of a single `match` expression.
100+
Matching these four possibilities instead requires two nested `match` expressions.

0 commit comments

Comments
 (0)