Skip to content

Commit 2c47d26

Browse files
authored
Merge pull request #4 from moonbitlang/0003-todo-cases
[ME-0003] Allow `...` in match cases
2 parents c94c9de + 6c1336b commit 2c47d26

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

proposals/0003-todo-cases.mbt.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Support `...` in match cases
2+
3+
* Proposal: [ME-0003](https://github.com/moonbitlang/moonbit-evolution/blob/0003-todo-cases/proposals/0003-todo-cases.mbt.md)
4+
* Author: [Yu-zh](https://github.com/Yu-zh)
5+
* Review and discussion: [Github issue](https://github.com/moonbitlang/moonbit-evolution/pull/4)
6+
7+
## Introduction
8+
9+
In MoonBit, we can use `...` as a placeholder for unimplemented code. For example:
10+
```moonbit
11+
fn init {
12+
fn unimplemented() {
13+
...
14+
}
15+
}
16+
```
17+
18+
The compiler emits a warning when the `...` is used, but the code will be
19+
further compiled. If `...` is reached at runtime, the program will panic.
20+
21+
## Allow `...` in match cases
22+
23+
Currently, `...` is only allowed when a statement is expected. Therefore, if we
24+
want leave the code in match cases unimplemented, we have to write `_ => ...`:
25+
```moonbit
26+
pub fn f1(x: Int) -> Unit {
27+
match x {
28+
0 => ()
29+
_ => ...
30+
}
31+
}
32+
```
33+
34+
We propose to extend the support to match cases so that we can write `...`
35+
directly:
36+
```moonbit
37+
pub fn f2(x: Int) -> Unit {
38+
match x {
39+
0 => ()
40+
...
41+
}
42+
}
43+
```

0 commit comments

Comments
 (0)