Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update newtype access syntax #326

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions moonbit-docs/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1216,12 +1216,12 @@ fn init {
}
```

Besides pattern matching, you can also use `.0` to extract the internal representation of newtypes:
Besides pattern matching, you can also use `._` to extract the internal representation of newtypes:

```moonbit
fn init {
let id: UserId = UserId(1)
let uid: Int = id.0
let uid: Int = id._
println(uid)
}
```
Expand Down Expand Up @@ -1609,7 +1609,7 @@ operator. For example:
```moonbit live
type T Int
type! E Int derive(Show)
fn f(self: T) -> Unit!E { raise E(self.0) }
fn f(self: T) -> Unit!E { raise E(self._) }
fn main {
let x = T(42)
try f!(x) { e => println(e) }
Expand Down Expand Up @@ -2093,7 +2093,7 @@ trait Animal {
type Duck String
fn Duck::make(name: String) -> Duck { Duck(name) }
fn speak(self: Duck) -> Unit {
println(self.0 + ": quack!")
println(self._ + ": quack!")
}

type Fox String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn bar() -> Int {

- 值字面量(例如布尔值、数字、字符、字符串、数组、元组、结构体)
- 算术、逻辑和比较运算
- 访问数组元素(例如 `a[0]`)、结构体字段(例如 `r.x`)或元组的元素(例如 `t.0`)
- 访问数组元素(例如 `a[0]`)、结构体字段(例如 `r.x`)或元组的元素(例如 `t._`)
- 变量和(大写字母开头的)枚举构造器
- 匿名局部函数定义
- `match` 和 `if` 表达式
Expand Down Expand Up @@ -1184,12 +1184,12 @@ fn init {
}
```

除了模式匹配,还可以使用 `.0` 提取新类型的内部表示:
除了模式匹配,还可以使用 `._` 提取新类型的内部表示:

```moonbit
fn init {
let id: UserId = UserId(1)
let uid: Int = id.0
let uid: Int = id._
println(uid)
}
```
Expand Down Expand Up @@ -1553,7 +1553,7 @@ fn main {
```moonbit live
type T Int
type! E Int derive(Show)
fn f(self: T) -> Unit!E { raise E(self.0) }
fn f(self: T) -> Unit!E { raise E(self._) }
fn main {
let x = T(42)
try f!(x) { e => println(e) }
Expand Down Expand Up @@ -2065,7 +2065,7 @@ trait Animal {
type Duck String
fn Duck::make(name: String) -> Duck { Duck(name) }
fn speak(self: Duck) -> Unit {
println(self.0 + ": quack!")
println(self._ + ": quack!")
}

type Fox String
Expand Down