Skip to content

Commit 81f4b23

Browse files
authored
Merge pull request #8 from moonbitlang/hongbo/tweak_refine_todo
tweak & refine todo proposal
2 parents 2c47d26 + 3ba5610 commit 81f4b23

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

proposals/0003-todo-cases.mbt.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Support `...` in match cases
22

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)
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)
66

77
## Introduction
88

99
In MoonBit, we can use `...` as a placeholder for unimplemented code. For example:
10+
1011
```moonbit
1112
fn init {
1213
fn unimplemented() {
@@ -22,22 +23,39 @@ further compiled. If `...` is reached at runtime, the program will panic.
2223

2324
Currently, `...` is only allowed when a statement is expected. Therefore, if we
2425
want leave the code in match cases unimplemented, we have to write `_ => ...`:
26+
2527
```moonbit
26-
pub fn f1(x: Int) -> Unit {
28+
pub fn f1(x : Int) -> Unit {
2729
match x {
2830
0 => ()
29-
_ => ...
31+
...
3032
}
3133
}
3234
```
3335

3436
We propose to extend the support to match cases so that we can write `...`
3537
directly:
38+
3639
```moonbit
37-
pub fn f2(x: Int) -> Unit {
40+
pub fn f2(x : Int) -> Unit {
3841
match x {
3942
0 => ()
4043
...
4144
}
4245
}
43-
```
46+
```
47+
48+
Note this means `...` can be used in any action case, including such cases:
49+
50+
```moonbit
51+
pub fn f3() -> Unit {
52+
...
53+
try {
54+
...
55+
} catch {
56+
...
57+
} noraise {
58+
...
59+
}
60+
}
61+
```

0 commit comments

Comments
 (0)