Skip to content

New Crowdin updates #1

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

Open
wants to merge 152 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
43fcb47
New translations array.mdx (Korean)
JiaeK Dec 16, 2022
2631a06
New translations debug.mdx (Korean)
JiaeK Dec 16, 2022
f324e3a
New translations float.mdx (Korean)
JiaeK Dec 16, 2022
2d87dab
New translations hash-map-int.mdx (Korean)
JiaeK Dec 16, 2022
da892c5
New translations hash-map-string.mdx (Korean)
JiaeK Dec 16, 2022
acb364a
New translations hash-map.mdx (Korean)
JiaeK Dec 16, 2022
8957f69
New translations hash-set-int.mdx (Korean)
JiaeK Dec 16, 2022
7867c0a
New translations hash-set-string.mdx (Korean)
JiaeK Dec 16, 2022
85dc378
New translations hash-set.mdx (Korean)
JiaeK Dec 16, 2022
2e2b5b3
New translations id.mdx (Korean)
JiaeK Dec 16, 2022
09851f4
New translations int.mdx (Korean)
JiaeK Dec 16, 2022
dca2c51
New translations list.mdx (Korean)
JiaeK Dec 16, 2022
e609a4b
New translations map-dict.mdx (Korean)
JiaeK Dec 16, 2022
385efe2
New translations map-int.mdx (Korean)
JiaeK Dec 16, 2022
9ea9bac
New translations map-string.mdx (Korean)
JiaeK Dec 16, 2022
31e8ca5
New translations map.mdx (Korean)
JiaeK Dec 16, 2022
9ec1edc
New translations mutable-map-int.mdx (Korean)
JiaeK Dec 16, 2022
a3930e7
New translations mutable-map-string.mdx (Korean)
JiaeK Dec 16, 2022
941af6e
New translations mutable-map.mdx (Korean)
JiaeK Dec 16, 2022
c13af95
New translations mutable-queue.mdx (Korean)
JiaeK Dec 16, 2022
84e1175
New translations mutable-set-int.mdx (Korean)
JiaeK Dec 16, 2022
af642c7
New translations mutable-set-string.mdx (Korean)
JiaeK Dec 16, 2022
5013f7f
New translations mutable-set.mdx (Korean)
JiaeK Dec 16, 2022
8b67a0f
New translations mutable-stack.mdx (Korean)
JiaeK Dec 16, 2022
3bb362d
New translations option.mdx (Korean)
JiaeK Dec 16, 2022
05d3a69
New translations range.mdx (Korean)
JiaeK Dec 16, 2022
107dfa5
New translations result.mdx (Korean)
JiaeK Dec 16, 2022
c6461f2
New translations set-dict.mdx (Korean)
JiaeK Dec 16, 2022
ad08db3
New translations set-int.mdx (Korean)
JiaeK Dec 16, 2022
3c540a9
New translations set-string.mdx (Korean)
JiaeK Dec 16, 2022
fc2c1c1
New translations set.mdx (Korean)
JiaeK Dec 16, 2022
b7be6ed
New translations sort-array-int.mdx (Korean)
JiaeK Dec 16, 2022
04a1927
New translations sort-array-string.mdx (Korean)
JiaeK Dec 16, 2022
4127218
New translations sort-array.mdx (Korean)
JiaeK Dec 16, 2022
87c4603
New translations storage.mdx (Korean)
JiaeK Dec 16, 2022
2e26de0
New translations storage2.mdx (Korean)
JiaeK Dec 16, 2022
5d58e12
New translations array-2.mdx (Korean)
JiaeK Dec 16, 2022
f37e6d1
New translations array.mdx (Korean)
JiaeK Dec 16, 2022
3d4fb18
New translations console.mdx (Korean)
JiaeK Dec 16, 2022
e952c1f
New translations date.mdx (Korean)
JiaeK Dec 16, 2022
561e338
New translations dict.mdx (Korean)
JiaeK Dec 16, 2022
7de2099
New translations exn.mdx (Korean)
JiaeK Dec 16, 2022
197a060
New translations float.mdx (Korean)
JiaeK Dec 16, 2022
7505ac0
New translations global.mdx (Korean)
JiaeK Dec 16, 2022
e9c474f
New translations int.mdx (Korean)
JiaeK Dec 16, 2022
15fab3e
New translations json.mdx (Korean)
JiaeK Dec 16, 2022
20d49bd
New translations list.mdx (Korean)
JiaeK Dec 16, 2022
a20e994
New translations math.mdx (Korean)
JiaeK Dec 16, 2022
d58ef65
New translations null-undefined.mdx (Korean)
JiaeK Dec 16, 2022
e913db3
New translations null.mdx (Korean)
JiaeK Dec 16, 2022
7636748
New translations nullable.mdx (Korean)
JiaeK Dec 16, 2022
6bd8db2
New translations obj.mdx (Korean)
JiaeK Dec 16, 2022
5ba8a01
New translations option.mdx (Korean)
JiaeK Dec 16, 2022
dffab5d
New translations promise.mdx (Korean)
JiaeK Dec 16, 2022
e9b889f
New translations re.mdx (Korean)
JiaeK Dec 16, 2022
c6cb558
New translations result.mdx (Korean)
JiaeK Dec 16, 2022
6de6db8
New translations string-2.mdx (Korean)
JiaeK Dec 16, 2022
0f2628b
New translations string.mdx (Korean)
JiaeK Dec 16, 2022
36ef569
New translations typed-array-2.mdx (Korean)
JiaeK Dec 16, 2022
4e30568
New translations typed-array-2_array-buffer.mdx (Korean)
JiaeK Dec 16, 2022
960134d
New translations typed-array-2_data-view.mdx (Korean)
JiaeK Dec 16, 2022
0b4f92c
New translations typed-array-2_float-32-array.mdx (Korean)
JiaeK Dec 16, 2022
a9ff999
New translations typed-array-2_float-64-array.mdx (Korean)
JiaeK Dec 16, 2022
5641f0e
New translations typed-array-2_int-16-array.mdx (Korean)
JiaeK Dec 16, 2022
7e22b70
New translations typed-array-2_int-32-array.mdx (Korean)
JiaeK Dec 16, 2022
c0f3748
New translations typed-array-2_int-8-array.mdx (Korean)
JiaeK Dec 16, 2022
3df8b21
New translations typed-array-2_uint-16-array.mdx (Korean)
JiaeK Dec 16, 2022
c4388bf
New translations typed-array-2_uint-32-array.mdx (Korean)
JiaeK Dec 16, 2022
49e3342
New translations typed-array-2_uint-8-array.mdx (Korean)
JiaeK Dec 16, 2022
76c39cd
New translations typed-array-2_uint-8-clamped-array.mdx (Korean)
JiaeK Dec 16, 2022
cb2007c
New translations typed-array.mdx (Korean)
JiaeK Dec 16, 2022
3e993ce
New translations typed-array_array-buffer.mdx (Korean)
JiaeK Dec 16, 2022
c2a17fd
New translations typed-array_data-view.mdx (Korean)
JiaeK Dec 16, 2022
537a720
New translations typed-array_float-32-array.mdx (Korean)
JiaeK Dec 16, 2022
bb21a38
New translations typed-array_float-64-array.mdx (Korean)
JiaeK Dec 16, 2022
fce5849
New translations typed-array_int-16-array.mdx (Korean)
JiaeK Dec 16, 2022
905a7b7
New translations typed-array_int-32-array.mdx (Korean)
JiaeK Dec 16, 2022
815766f
New translations typed-array_int-8-array.mdx (Korean)
JiaeK Dec 16, 2022
9ff6631
New translations typed-array_type-s.mdx (Korean)
JiaeK Dec 16, 2022
3cfecb1
New translations typed-array_uint-16-array.mdx (Korean)
JiaeK Dec 16, 2022
a0f253f
New translations typed-array_uint-32-array.mdx (Korean)
JiaeK Dec 16, 2022
335f4f0
New translations typed-array_uint-8-array.mdx (Korean)
JiaeK Dec 16, 2022
524539a
New translations typed-array_uint-8-clamped-array.mdx (Korean)
JiaeK Dec 16, 2022
0dfde56
New translations types.mdx (Korean)
JiaeK Dec 16, 2022
854bf7c
New translations undefined.mdx (Korean)
JiaeK Dec 16, 2022
b9787c9
New translations vector.mdx (Korean)
JiaeK Dec 16, 2022
ad2cccc
New translations belt.mdx (Korean)
JiaeK Dec 16, 2022
a0b8b91
New translations dom.mdx (Korean)
JiaeK Dec 16, 2022
fcbb2e7
New translations js.mdx (Korean)
JiaeK Dec 16, 2022
3933219
New translations api.mdx (Korean)
JiaeK Dec 16, 2022
5a58bf9
New translations array-and-list.mdx (Korean)
JiaeK Dec 16, 2022
c95b888
New translations attribute.mdx (Korean)
JiaeK Dec 16, 2022
8ab718b
New translations bind-to-global-js-values.mdx (Korean)
JiaeK Dec 16, 2022
12c1a57
New translations bind-to-js-function.mdx (Korean)
JiaeK Dec 16, 2022
9d21dea
New translations bind-to-js-object.mdx (Korean)
JiaeK Dec 16, 2022
874c489
New translations browser-support-polyfills.mdx (Korean)
JiaeK Dec 16, 2022
a60db39
New translations build-configuration-schema.mdx (Korean)
JiaeK Dec 16, 2022
e45b1b5
New translations build-configuration.mdx (Korean)
JiaeK Dec 16, 2022
7a6da1f
New translations build-external-stdlib.mdx (Korean)
JiaeK Dec 16, 2022
617466c
New translations build-overview.mdx (Korean)
JiaeK Dec 16, 2022
aac21af
New translations build-performance.mdx (Korean)
JiaeK Dec 16, 2022
1c36284
New translations build-pinned-dependencies.mdx (Korean)
JiaeK Dec 16, 2022
0898547
New translations control-flow.mdx (Korean)
JiaeK Dec 16, 2022
611b927
New translations converting-from-js.mdx (Korean)
JiaeK Dec 16, 2022
41aff22
New translations editor-plugins.mdx (Korean)
JiaeK Dec 16, 2022
96012bb
New translations embed-raw-javascript.mdx (Korean)
JiaeK Dec 16, 2022
227b374
New translations exception.mdx (Korean)
JiaeK Dec 16, 2022
84e5011
New translations extensible-variant.mdx (Korean)
JiaeK Dec 16, 2022
eeea09d
New translations external.mdx (Korean)
JiaeK Dec 16, 2022
ece271f
New translations faq.mdx (Korean)
JiaeK Dec 16, 2022
f7d8b24
New translations function.mdx (Korean)
JiaeK Dec 16, 2022
3aee064
New translations generate-converters-accessors.mdx (Korean)
JiaeK Dec 16, 2022
d0b034f
New translations import-export.mdx (Korean)
JiaeK Dec 16, 2022
eef2b8c
New translations import-from-export-to-js.mdx (Korean)
JiaeK Dec 16, 2022
69e54a3
New translations inlining-constants.mdx (Korean)
JiaeK Dec 16, 2022
e92e2ba
New translations installation.mdx (Korean)
JiaeK Dec 16, 2022
39db30a
New translations interop-cheatsheet.mdx (Korean)
JiaeK Dec 16, 2022
cd32344
New translations interop-with-js-build-systems.mdx (Korean)
JiaeK Dec 16, 2022
0a2d74c
New translations introduction.mdx (Korean)
JiaeK Dec 16, 2022
c8e3871
New translations json.mdx (Korean)
JiaeK Dec 16, 2022
33f5be3
New translations jsx.mdx (Korean)
JiaeK Dec 16, 2022
45bcc1c
New translations lazy-values.mdx (Korean)
JiaeK Dec 16, 2022
ce7d399
New translations let-binding.mdx (Korean)
JiaeK Dec 16, 2022
f1852a1
New translations libraries.mdx (Korean)
JiaeK Dec 16, 2022
91fced2
New translations migrate-from-bucklescript-reason.mdx (Korean)
JiaeK Dec 16, 2022
c5c381f
New translations module.mdx (Korean)
JiaeK Dec 16, 2022
8068f36
New translations mutation.mdx (Korean)
JiaeK Dec 16, 2022
64a0bd5
New translations newcomer-examples.mdx (Korean)
JiaeK Dec 16, 2022
a221a6f
New translations null-undefined-option.mdx (Korean)
JiaeK Dec 16, 2022
4efb83d
New translations object.mdx (Korean)
JiaeK Dec 16, 2022
9462be7
New translations overview.mdx (Korean)
JiaeK Dec 16, 2022
dab9ff5
New translations pattern-matching-destructuring.mdx (Korean)
JiaeK Dec 16, 2022
90977f8
New translations pipe.mdx (Korean)
JiaeK Dec 16, 2022
72c3c0c
New translations polymorphic-variant.mdx (Korean)
JiaeK Dec 16, 2022
64657aa
New translations primitive-types.mdx (Korean)
JiaeK Dec 16, 2022
ae7c00e
New translations project-structure.mdx (Korean)
JiaeK Dec 16, 2022
ccb6a4a
New translations promise.mdx (Korean)
JiaeK Dec 16, 2022
f304c88
New translations record.mdx (Korean)
JiaeK Dec 16, 2022
84ad585
New translations reserved-keywords.mdx (Korean)
JiaeK Dec 16, 2022
8cd5680
New translations shared-data-types.mdx (Korean)
JiaeK Dec 16, 2022
569417e
New translations try.mdx (Korean)
JiaeK Dec 16, 2022
847a2fd
New translations tuple.mdx (Korean)
JiaeK Dec 16, 2022
15773c1
New translations type.mdx (Korean)
JiaeK Dec 16, 2022
7239563
New translations unboxed.mdx (Korean)
JiaeK Dec 16, 2022
408c757
New translations use-illegal-identifier-names.mdx (Korean)
JiaeK Dec 16, 2022
c26577b
New translations variant.mdx (Korean)
JiaeK Dec 16, 2022
7ebce01
New translations warning-numbers.mdx (Korean)
JiaeK Dec 16, 2022
c7839e4
New translations installation.mdx (Korean)
JiaeK Dec 16, 2022
6e8c9f2
New translations introduction.mdx (Korean)
JiaeK Dec 17, 2022
b40e934
New translations introduction.mdx (Korean)
JiaeK Dec 17, 2022
71eceb6
New translations introduction.mdx (Korean)
JiaeK Dec 19, 2022
b4267c0
New translations introduction.mdx (Korean)
JiaeK Dec 19, 2022
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
15 changes: 15 additions & 0 deletions ko/pages/docs/manual/latest/api.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Overview

ReScript ships 3 modules in its standard library.

- [Js](api/js): bindings for all your familiar JavaScript APIs.
- [Belt](api/belt): extra collections and helpers not available in JavaScript.
- [Dom](api/dom): Dom related types and modules.

Usage heuristics:

- Default to using the `Js` module. Most of the APIs in it are runtime-free and compile down to clean, readable JavaScript, which is our priority.
- For other APIs that aren't available in regular JavaScript (and thus don't exist in our `Js` bindings), use Belt. For example, prefer `Js.Array2` over `Belt.Array`.
- The `Dom` module contains our standardized types used by various userland DOM bindings. Due to the complexity of DOM, we don't mind that you ignore this module and build your application-specific DOM bindings.

**Note**: we do not recommend other userland standard library alternatives (unless it's DOM bindings). These cause confusion and split points for the community.
177 changes: 177 additions & 0 deletions ko/pages/docs/manual/latest/api/belt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Belt

The ReScript standard library.

Belt is currently mostly covering collection types. It has no string or date functions yet, although Belt.String is in the works. In the meantime, use [Js.String](js/string) for string functions and [Js.Date](js/date) for date functions.

## Motivation

Belt provides:

- The **highest quality** immutable data structures in JavaScript.
- Safety by default: A Belt function will never throw exceptions, unless it is indicated explicitly in the function name (suffix "Exn").
- Better performance and smaller code size running on the JS platform.
- Ready for [Tree Shaking](https://webpack.js.org/guides/tree-shaking/).

## Usage

To use modules from Belt, either refer to them by their fully qualified name (`Belt.List`, `Belt.Array` etc.) or open the `Belt` module by putting

```res
open Belt
```

at the top of your source files. After opening Belt this way, `Array` will refer to `Belt.Array`, `List` will refer to `Belt.List` etc. in the subsequent code.

If you want to open Belt globally for all files in your project instead, you can put

```json
"bsc-flags": ["-open Belt"],
```

into your `bsconfig.json`.

**Note**: this is the **only** `open` we encourage.

Example usage:

```res
let someNumbers = [1, 1, 4, 2, 3, 6, 3, 4, 2]

let greaterThan2UniqueAndSorted =
someNumbers
->Belt.Array.keep(x => x > 2)
// convert to and from set to make values unique
->Belt.Set.Int.fromArray
->Belt.Set.Int.toArray // output is already sorted

Js.log2("result", greaterThan2UniqueAndSorted)
```

## Curried vs. Uncurried Callbacks

For functions taking a callback parameter, there are usually two versions available:

- curried (no suffix)
- uncurried (suffixed with `U`)

E.g.:

```res
let forEach: (t<'a>, 'a => unit) => unit

let forEachU: (t<'a>, (. 'a) => unit) => unit
```

The uncurried version will be faster in some cases, but for simplicity we recommend to stick with the curried version unless you need the extra performance.

The two versions can be invoked as follows:

```
["a", "b", "c"]->Belt.Array.forEach(x => Js.log(x))

["a", "b", "c"]->Belt.Array.forEachU((. x) => Js.log(x))
```

## Specialized Collections

For collections types like set or map, Belt provides both a generic module as well as specialized, more efficient implementations for string and int keys.

For example, Belt has the following set modules:

- [Belt.Set](belt/set)
- [Belt.Set.Int](belt/set-int)
- [Belt.Set.String](belt/set-string)

## Implementation Details

### Array access runtime safety

One common confusion comes from the way Belt handles array access. It differs from than the default standard library's.

```res
let letters = ["a", "b", "c"]
let a = letters[0] // a == "a"
let capitalA = Js.String.toUpperCase(a)
let k = letters[10] // Raises an exception! The 10th index doesn't exist.
```

Because Belt avoids exceptions and returns `options` instead, this code behaves differently:

```res
open Belt
let letters = ["a", "b", "c"]
let a = letters[0] // a == Some("a")
let captialA = Js.String.toUpperCase(a) // Type error! This code will not compile.
let k = letters[10] // k == None
```

Although we've fixed the problem where `k` raises an exception, we now have a type error when trying to capitalize `a`. There are a few things going on here:

- Reason transforms array index access to the function `Array.get`. So `letters[0]` is the same as `Array.get(letters, 0)`.
- The compiler uses whichever `Array` module is in scope. If you `open Belt`, then it uses `Belt.Array`.
- `Belt.Array.get` returns values wrapped in options, so `letters[0] == Some("a")`.

Fortunately, this is easy to fix:

```res example
open Belt
let letters = ["a", "b", "c"]
let a = letters[0]

// Use a switch statement:
let capitalA =
switch a {
| Some(a) => Some(Js.String.toUpperCase(a))
| None => None
}

let k = letters[10] // k == None
```

With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors!

### A Special Encoding for Collection Safety

When we create a collection library for a custom data type we need a way to provide a comparator function. Take Set for example, suppose its element type is a pair of ints, it needs a custom compare function that takes two tuples and returns their order. The Set could not just be typed as Set.t (int \* int) , its customized compare function needs to manifest itself in the signature, otherwise, if the user creates another customized compare function, the two collection could mix which would result in runtime error.

We use a phantom type to solve the problem:

```res
module Comparable1 =
Belt.Id.MakeComparable(
{
type t = (int, int)
let cmp = ((a0, a1), (b0, b1)) =>
switch Pervasives.compare(a0, b0) {
| 0 => Pervasives.compare(a1, b1)
| c => c
}
}
)

let mySet1 = Belt.Set.make(~id=module(Comparable1))

module Comparable2 =
Belt.Id.MakeComparable(
{
type t = (int, int)
let cmp = ((a0, a1), (b0, b1)) =>
switch Pervasives.compare(a0, b0) {
| 0 => Pervasives.compare(a1, b1)
| c => c
}
}
)

let mySet2 = Belt.Set.make(~id=module(Comparable2))
```

Here, the compiler would infer `mySet1` and `mySet2` having different type, so e.g. a `merge` operation that tries to merge these two sets will correctly fail.

```res
let mySet1: t<(int, int), Comparable1.identity>
let mySet2: t<(int, int), Comparable2.identity>
```

`Comparable1.identity` and `Comparable2.identity` are not the same using our encoding scheme.
Loading