Skip to content

Commit

Permalink
add bytes literals. @json.Jsonvalue to Json
Browse files Browse the repository at this point in the history
  • Loading branch information
notch1p committed Aug 22, 2024
1 parent 8d8cde8 commit 862325f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions moonbit-docs/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ let zero = '\u{30}'
let zero = '\u0030'
```

### Byte
### Byte(s)

A byte literal in MoonBit is either a single ASCII character or a single escape enclosed in single quotes `'`, and preceded by the character `b`. Byte literals are of type `Byte`. For example:

Expand All @@ -713,6 +713,16 @@ fn main {
}
```

A `Bytes` is a sequence of bytes. Similar to byte, bytes literals have the form of `b"..."`. For example:

```moonbit live
fn main {
let b1 : Bytes = b"abcd"
let b2 = b"\x61\x62\x63\x64"
println(b1 == b2) // true
}
```

### Tuple

A tuple is a collection of finite values constructed using round brackets `()` with the elements separated by commas `,`. The order of elements matters; for example, `(1,true)` and `(true,1)` have different types. Here's an example:
Expand Down Expand Up @@ -782,10 +792,10 @@ Currently keys in map literal syntax must be constant. `Map`s can also be destru
## Json literal

MoonBit supports convenient json handling by overloading literals.
When the expected type of an expression is `@json.JsonValue`, number, string, array and map literals can be directly used to create json data:
When the expected type of an expression is `Json`, number, string, array and map literals can be directly used to create json data:

```moonbit
let moon_pkg_json_example : @json.JsonValue = {
let moon_pkg_json_example : Json = {
"import": [ "moonbitlang/core/builtin", "moonbitlang/core/coverage" ],
"test-import": [ "moonbitlang/core/random" ]
}
Expand Down Expand Up @@ -1166,7 +1176,7 @@ match map {

### Json Pattern

When the matched value has type `@json.JsonValue`, literal patterns can be used directly:
When the matched value has type `Json`, literal patterns can be used directly:

```moonbit
match json {
Expand Down

0 comments on commit 862325f

Please sign in to comment.