mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
Merge pull request #172 from GreasySlug/fix/md_links
WIP: Fix broken links in doc directory
This commit is contained in:
commit
3adc6bafeb
71 changed files with 402 additions and 86 deletions
|
@ -38,4 +38,4 @@ Erg のバグだと思われる動作を見つけた場合は、[報告](https:/
|
|||
|
||||
Ergチームや言語で標準とされるスタイルのコードを書いてください。
|
||||
|
||||
## [行動規範](./CODE_OF_CONDUCT.md)
|
||||
## [行動規範](./../CODE_OF_CONDUCT/CODE_OF_CONDUCT_JA.md)
|
||||
|
|
|
@ -38,4 +38,4 @@
|
|||
|
||||
请以 Erg 团队和语言标准化的风格编写代码。
|
||||
|
||||
## [行为准则](./CODE_OF_CONDUCT.md)
|
||||
## [行为准则](../CODE_OF_CONDUCT/CODE_OF_CONDUCT_zh-CN.md)
|
||||
|
|
|
@ -38,4 +38,4 @@
|
|||
|
||||
請以 Erg 團隊和語言標準化的風格編寫代碼。
|
||||
|
||||
## [行為準則](./CODE_OF_CONDUCT.md)
|
||||
## [行為準則](../CODE_OF_CONDUCT/CODE_OF_CONDUCT_zh-TW.md)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# Index
|
||||
|
||||
## [consts](./consts.md)
|
||||
|
||||
## [funcs](./funcs.md)
|
||||
|
||||
## [operations](./operators.md)
|
||||
|
||||
## [procs](./procs.md)
|
||||
|
||||
## [special](./special.md)
|
||||
|
||||
## [types](./types.md)
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## Overloading (ad-hoc polymorphism)
|
||||
|
||||
It was abandoned because it can be replaced by parametric + subtyping polymorphism, and it is incompatible with Python's semantics. See [overload](../syntax/type/overloading.md) article for details.
|
||||
It was abandoned because it can be replaced by parametric + subtyping polymorphism, and it is incompatible with Python's semantics. See [overload](../syntax/type/advanced/overloading.md) article for details.
|
||||
|
||||
## Ownership system with explicit lifetime
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# Index
|
||||
|
||||
## [abandoned](./abandoned.md)
|
||||
|
||||
## [architecture](./architecture.md)
|
||||
|
||||
## [error](./errors.md)
|
||||
|
||||
## [hir](./hir.md)
|
||||
|
||||
## [inference](./inference.md)
|
||||
|
||||
## [overview](./overview.md)
|
||||
|
||||
## [parsing](./parsing.md)
|
||||
|
||||
## [refinement_subtyping](./refinement_subtyping.md)
|
||||
|
||||
## [TODO_hint](./TODO_hint.md)
|
||||
|
||||
## [TODO_recov_suggest](./TODO_recov_suggest.md)
|
||||
|
||||
## [TODO_warn](./TODO_warn.md)
|
||||
|
||||
## [trait_method_resolving](./trait_method_resolving.md)
|
||||
|
||||
## [transpile](./transpile.md)
|
||||
|
||||
## [type_var_normalization.](type_var_normalization.md)
|
|
@ -63,7 +63,7 @@ line 3. Call {obj: print!, args: [v]}
|
|||
|
||||
## Implementation of type variables
|
||||
|
||||
Type variables were originally expressed as follows in `Type` of [ty.rs](../../src/common/ty.rs). It's now implemented in a different way, but it's essentially the same idea, so I'll consider this implementation in a more naive way.
|
||||
Type variables were originally expressed as follows in `Type` of [ty.rs]. It's now implemented in a different way, but it's essentially the same idea, so I'll consider this implementation in a more naive way.
|
||||
`RcCell<T>` is a wrapper type for `Rc<RefCell<T>>`.
|
||||
|
||||
```rust
|
||||
|
@ -112,7 +112,7 @@ After that, give the type of the argument to get the target type. This operation
|
|||
In addition, the operation that obtains the return type if the expression is a call is denoted as `subst_call_ret`. The first argument is a list of argument types, the second argument is the type to assign to.
|
||||
|
||||
The type substitution rule `{?T --> X}` means to rewrite `?T` and `X` to be of the same type. This operation is called __Unification__. `X` can also be a type variable.
|
||||
A detailed unification algorithm is described in [separate section](./unification.md). We will denote the unify operation as `unify`.
|
||||
A detailed unification algorithm is described in [separate section]. We will denote the unify operation as `unify`.
|
||||
|
||||
```python
|
||||
unify(?T, Int) == Ok(()) # ?T == (Int)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# Index
|
||||
|
||||
## [branches](branches.md)
|
||||
|
||||
## [build_features](build_features.md)
|
||||
|
||||
## [directories](directories.md)
|
||||
|
||||
## [doc_guideline](doc_guideline.md)
|
||||
|
||||
## [env](env.md)
|
||||
|
||||
## [i18n_messages](i18n_messages.md)
|
||||
|
||||
## [rust_code_guideline](rust_code_guideline.md)
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
This FAQ is intended for the general Erg beginner.
|
||||
For individual (common) technical issues, please refer to [here](./faq_technical.md) for individual (common) technical issues, and
|
||||
[Here](./dev_guide/faq_syntax.md) for more information.
|
||||
[here](./faq_syntax.md) for more information.
|
||||
|
||||
## What does it mean that Erg is a Python compatible language?
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## Erg memory management model
|
||||
|
||||
Use ownership in CPython backend + Python memory management model (though circular references in Erg code will not be handled by GC [see details](../syntax/18_ownership.md/#circular-references)
|
||||
Use ownership in CPython backend + Python memory management model (though circular references in Erg code will not be handled by GC [see details](./syntax/18_ownership.md/#circular-references)
|
||||
|
||||
Using ownership + [Perceus](https://www.microsoft.com/en-us/research/uploads/prod/2020/11/perceus-tr-v1.pdf) memory in Erg's own virtual machine (Dyne) Management model, if Erg code uses the Python API then the Erg code uses the tracking garbage collection memory management model
|
||||
|
||||
|
@ -12,7 +12,7 @@ Regardless of the backend, the difference in memory management will not need any
|
|||
|
||||
__Notice__:Erg's motivation for introducing an ownership system is not for "memory management without relying on GC" like Rust.
|
||||
The aim of Erg's ownership system is ``localization of mutable state''. Erg has a notion of ownership attached to mutable objects.
|
||||
This is because shared mutable state is prone to bugs and even violates type safety (see [here](../syntax/type/advanced/shared.md#SharedReference)). It's a judgmental decision.
|
||||
This is because shared mutable state is prone to bugs and even violates type safety (see [here](./syntax/type/advanced/shared.md#SharedReference)). It's a judgmental decision.
|
||||
|
||||
## Why are the braces around type parameters || instead of <> or []?
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
This section answers technical questions about using the Erg language. In other words, it contains questions that begin with What or Which, and questions that can be answered with Yes/No.
|
||||
|
||||
For more information on how the grammar was determined, see [here](./dev_guide/faq_syntax.md) for the underlying syntax decisions, and [here](./dev_guide/../faq_general.md).
|
||||
For more information on how the grammar was determined, see [here](./faq_syntax.md) for the underlying syntax decisions, and [here](./faq_general.md).
|
||||
|
||||
## Is there an exception mechanism in Erg?
|
||||
|
||||
A: No. Erg uses the `Result` type instead. See [here](./dev_guide/faq_syntax.md) for why Erg does not have an exception mechanism.
|
||||
A: No. Erg uses the `Result` type instead. See [here](./faq_syntax.md) for why Erg does not have an exception mechanism.
|
||||
|
||||
## Does Erg have a type equivalent to TypeScript's `Any`?
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# Index
|
||||
|
||||
## [bytecode_instructions](./bytecode_instructions.md)
|
||||
|
||||
## [bytecode_specification](./bytecode_specification.md)
|
||||
|
||||
## [class_system](./class_system.md)
|
|
@ -9,7 +9,7 @@
|
|||
>
|
||||
> [The Erg Book traditional Chinese edition](https://erg-lang.github.io/the-erg-book/zh_TW/)
|
||||
|
||||
This document describes the basic syntax of Erg. The [Standard API](./API/index.md) and [internal documents for Erg contributors](./dev_guide/index.md) are located in another directory.
|
||||
This document describes the basic syntax of Erg. The [Standard API](../API/index.md) and [internal documents for Erg contributors](../dev_guide/index.md) are located in another directory.
|
||||
|
||||
## Hello, World!
|
||||
|
||||
|
|
|
@ -65,18 +65,18 @@ Each of these literals has its own documentation describing them separately, so
|
|||
[], [1], [1, 2, 3], ["1", "2",], [1, "1", True, [1]], ...
|
||||
```
|
||||
|
||||
### [Dict Literal](./11_dict.md)
|
||||
|
||||
```python
|
||||
{:}, {"one": 1}, {"one": 1, "two": 2}, {"1": 1, "2": 2}, {1: "1", 2: True, "three": [1]}, ...
|
||||
```
|
||||
|
||||
### [Tuple Literal](./12_tuple.md)
|
||||
### [Tuple Literal](./11_tuple.md)
|
||||
|
||||
```python
|
||||
(), (1, 2, 3), (1, "hello", True), ...
|
||||
```
|
||||
|
||||
### [Dict Literal](./12_dict.md)
|
||||
|
||||
```python
|
||||
{:}, {"one": 1}, {"one": 1, "two": 2}, {"1": 1, "2": 2}, {1: "1", 2: True, "three": [1]}, ...
|
||||
```
|
||||
|
||||
### [Record Literal](./13_record.md)
|
||||
|
||||
```python
|
||||
|
|
|
@ -18,7 +18,7 @@ The difference from JavaScript object literals is that they are not accessible a
|
|||
This is because access to the value is determined at compile-time, and because dictionaries and records are different things. In other words, `{"name": "John"}` is a Dict and `{name = "John"}` is a record.
|
||||
So how should we use dictionaries and records?
|
||||
In general, we recommend using records. Records have the advantages of being checked at compile-time for the existence of elements and of being able to specify __visibility_.
|
||||
Specifying visibility is equivalent to specifying public/private in Java and other languages. For details, see [visibility](./15_visibility.md) for details.
|
||||
Specifying visibility is equivalent to specifying public/private in Java and other languages. For details, see [visibility](./19_visibility.md) for details.
|
||||
|
||||
```python
|
||||
a = {x = 1; .y = x + 1}
|
||||
|
|
|
@ -49,7 +49,7 @@ log s2, s1 # !"HELLO hello"
|
|||
We take advantage of the fact that immutable objects can be referenced from multiple places and convert mutable objects to immutable objects.
|
||||
This is called freezing. Freezing is used, for example, when creating an iterator from a mutable array.
|
||||
Since you can't create an iterator directly from a mutable array, convert it to an immutable array.
|
||||
If you don't want to destroy the array, use the [`.freeze_map` method](./type/mut.md).
|
||||
If you don't want to destroy the array, use the [`.freeze_map` method](./type/18_mut.md).
|
||||
|
||||
```python
|
||||
# Compute the sum of the values produced by the iterator
|
||||
|
|
|
@ -99,7 +99,7 @@ However, the smallest type can be defined as a single type, in this case `{1}`.
|
|||
Objects can use patch methods as well as class methods.
|
||||
Erg does not allow you to add class methods, but you can use [patch](./07_patch.md) to extend a class.
|
||||
|
||||
You can also inherit from existing classes ([Inheritable](./../27_decorator.md/#inheritable) class).
|
||||
You can also inherit from existing classes ([Inheritable](../29_decorator.md#inheritable) class).
|
||||
You can create an inherited class by using `Inherit`. The type on the left-hand side is called the derived class, and the argument type of `Inherit` on the right-hand side is called the base class (inherited class).
|
||||
|
||||
```python
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Refinement type is a type constrained by a predicate expression. Enumeration types and interval types are syntax sugar of refinement types.
|
||||
|
||||
The standard form of a refinement type is `{Elem: Type | (Pred)*}`. This means that the type is a type whose elements are `Elem` satisfying `Pred`.
|
||||
The type that can be used for the sifting type is [Const type](./advanced/const.md) only.
|
||||
The type that can be used for the sifting type is [Const type] only.
|
||||
|
||||
```python
|
||||
Nat = 0.. _
|
||||
|
|
|
@ -31,7 +31,7 @@ tuple_map f: (|T: Type| T -> T), tup: (Int, Str) = (f(tup.0), f(tup.1))
|
|||
assert tuple_map(i -> i * 2, (1, "a")) == (2, "aa")
|
||||
```
|
||||
|
||||
A type of the form `{(type) | (list of type variables)}` is called a universal type (see [Universal type](./../quantified.md) for details).
|
||||
A type of the form `{(type) | (list of type variables)}` is called a universal type (see [Universal type](../15_quantified.md) for details).
|
||||
The `id` function we have seen so far is a typical universal function = polycorrelation function.
|
||||
|
||||
```python
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
A marker added to the end of an identifier to indicate that it is a procedure or variable type.
|
||||
Or the mutating operator.
|
||||
|
||||
### [#](../syntax/00_basic.md/#comments)
|
||||
### [#](./syntax/00_basic.md#comments)
|
||||
|
||||
### $
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# Index
|
||||
|
||||
## [build](./build.md)
|
||||
|
||||
## [env](./env.md)
|
||||
|
||||
## [fmt](./fmt.md)
|
||||
|
||||
## [install](./install.md)
|
||||
|
||||
## [pack](./pack.md)
|
||||
|
||||
## [repl](./repl.md)
|
||||
|
||||
## [test](./test.md)
|
|
@ -1,2 +1,15 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [consts](./consts.md)
|
||||
|
||||
## [funcs](./funcs.md)
|
||||
|
||||
## [operations](./operators.md)
|
||||
|
||||
## [procs](./procs.md)
|
||||
|
||||
## [special](./special.md)
|
||||
|
||||
## [types](./types.md)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
## オーバーロード(アドホック多相)
|
||||
|
||||
パラメトリック+サブタイピング多相で代替できること、Pythonの意味論との相性の悪さなどを理由に放棄された。詳しくは[overload](../syntax/type/overloading.md)の記事を参照。
|
||||
パラメトリック+サブタイピング多相で代替できること、Pythonの意味論との相性の悪さなどを理由に放棄された。詳しくは[overload](../syntax/type/advanced/overloading.md)の記事を参照。
|
||||
|
||||
## 明示的ライフタイム付き所有権システム
|
||||
|
||||
|
|
|
@ -1,2 +1,31 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/compiler/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [abandoned](./abandoned.md)
|
||||
|
||||
## [architecture](./architecture.md)
|
||||
|
||||
## [error](./errors.md)
|
||||
|
||||
## [hir](./hir.md)
|
||||
|
||||
## [inference](./inference.md)
|
||||
|
||||
## [overview](./overview.md)
|
||||
|
||||
## [parsing](./parsing.md)
|
||||
|
||||
## [refinement_subtyping](./refinement_subtyping.md)
|
||||
|
||||
## [TODO_hint](./TODO_hint.md)
|
||||
|
||||
## [TODO_recov_suggest](./TODO_recov_suggest.md)
|
||||
|
||||
## [TODO_warn](./TODO_warn.md)
|
||||
|
||||
## [trait_method_resolving](./trait_method_resolving.md)
|
||||
|
||||
## [transpile](./transpile.md)
|
||||
|
||||
## [type_var_normalization.](type_var_normalization.md)
|
|
@ -98,7 +98,7 @@ pub enum Type {
|
|||
未束縛型変数`?T`を一般化する操作を`gen`と表すことにします。このとき、得られる一般化型変数を`|T: Type| T`とします。
|
||||
型理論では、量化された型、例えば多相関数型`α->α`はその前に`∀α.`を付けて区別します(∀のような記号を(全称)量化子といいます)。
|
||||
このような表現(e.g. `∀α. α->α`)を型スキームと呼びます。Ergでの型スキームは`|T: Type| T -> T`などと表されます。
|
||||
型スキームは、通常は第一級の型とはみなされません。そのように型システムを構成すると、型推論がうまく動作しなくなる場合があるためです。ただしErgでは一定の条件下で第一級の型とみなせます。詳細は[ランク2型](../syntax/type/advanced/rank2type.md)を参照してください。
|
||||
型スキームは、通常は第一級の型とはみなされません。そのように型システムを構成すると、型推論がうまく動作しなくなる場合があるためです。ただしErgでは一定の条件下で第一級の型とみなせます。詳細は[ランク2型](../syntax/type/advanced/_rank2type.md)を参照してください。
|
||||
|
||||
さて、得られた型スキーム(e.g. `'T -> 'T (idの型スキーム)`)を使用箇所(e.g. `id 1`, `id True`)の型推論で使う際は、一般化を解除する必要があります。この逆変換を __具体化(instantiation)__ と呼びます。操作は`inst`と呼ぶことにします。
|
||||
|
||||
|
@ -114,7 +114,7 @@ inst 'T = ?T (?T ∉ Γ)
|
|||
さらに、その式が呼び出しの場合に戻り値型を得る操作を`subst_call_ret`と表します。第1引数は引数型のリスト、第2引数は代入先の型です。
|
||||
|
||||
型代入規則`{?T --> X}`は、`?T`と`X`を同一の型とみなすよう書き換えるという意味です。この操作を __単一化(Unification)__ といいます。`X`は型変数もありえます。
|
||||
単一化の詳しいアルゴリズムは[別の項](./unification.md)で解説します。単一化操作は`unify`と表すことにします。
|
||||
単一化の詳しいアルゴリズムは[別の項]で解説します。単一化操作は`unify`と表すことにします。
|
||||
|
||||
```python
|
||||
unify(?T, Int) == Ok(()) # ?T == (Int)
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/dev_guide/index.md&commit_hash=7d43acdf0e2b71528b038b9a8e70be6c93831f96)
|
||||
|
||||
## [branches](./branches.md)
|
||||
|
||||
## [build_features](./build_features.md)
|
||||
|
||||
## [directories](./directories.md)
|
||||
|
||||
## [doc_guideline](./doc_guideline.md)
|
||||
|
||||
## [env](./env.md)
|
||||
|
||||
## [i18n_messages](./i18n_messages.md)
|
||||
|
||||
## [rust_code_guideline](./rust_code_guideline.md)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
このFAQは一般のErg入門者向けです。
|
||||
個別の(よくある)技術的な問題については[こちら](./faq_technical.md)を、文法の決定経緯(なぜこのような文法になったのか)などについては
|
||||
[こちら](./dev_guide/why.md)を参照してください。
|
||||
[こちら](./faq_syntax.md)を参照してください。
|
||||
|
||||
## ErgはPython互換言語というのはどういう意味なのですか?
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ LLVM では、WASM バックエンドは所有権 + [Perceus](https://www.micros
|
|||
|
||||
__知らせ__:Ergが所有権システムを導入した動機は、Rustのような「GCに頼らないメモリ管理」のためではないからです。
|
||||
Ergが所有権システムを導入した狙いは「可変状態の局所化」です。Ergでは、可変オブジェクトに所有権の概念がついています。
|
||||
これは、共有可変状態がバグの温床になりやすく、さらに型安全性まで侵害すること(詳しくは[こちら](../syntax/type/advanced/shared.md#共有参照SharedReference)を参照)をみての判断です。
|
||||
これは、共有可変状態がバグの温床になりやすく、さらに型安全性まで侵害すること(詳しくは[こちら](./syntax/type/advanced/shared.md)を参照)をみての判断です。
|
||||
|
||||
## なぜ型パラメータを囲むカッコが<>や[]ではなく||なのですか?
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
本項はErg言語を使用する上での技術的な質問に答えるものです。すなわち、WhatやWhichで始まる質問、Yes/Noで答えられる質問を載せています。
|
||||
|
||||
根本的な文法の決定経緯については[こちら](./dev_guide/faq_syntax.md)を、なぜこの言語を作ったのか、この機能はどのように実装されているのかなど、より大きな話題は[こちら](./dev_guide/../faq_general.md)を参照してください。
|
||||
根本的な文法の決定経緯については[こちら](./faq_syntax.md)を、なぜこの言語を作ったのか、この機能はどのように実装されているのかなど、より大きな話題は[こちら](./faq_general.md)を参照してください。
|
||||
|
||||
## Ergに例外機構はないのですか?
|
||||
|
||||
A: ありません。Ergでは代わりに`Result`型を使います。なぜErgに例外機構がないのかは[こちら](./dev_guide/faq_syntax.md#なぜergには例外機構がないのですか)を参照してください。
|
||||
A: ありません。Ergでは代わりに`Result`型を使います。なぜErgに例外機構がないのかは[こちら](./faq_syntax.md#なぜergには例外機構がないのですか)を参照してください。
|
||||
|
||||
## ErgにはTypeScriptのAnyに相当する型はないのですか?
|
||||
|
||||
|
|
|
@ -1,2 +1,9 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/python/index.md&commit_hash=9f6a4a43fcf7e4f58cabe6e5a7546820fd9f5ff4)
|
||||
|
||||
## [bytecode_instructions](./bytecode_instructions.md)
|
||||
|
||||
## [bytecode_specification](./bytecode_specification.md)
|
||||
|
||||
## [class_system](./class_system.md)
|
|
@ -71,18 +71,18 @@ assert 1e-10 == 0.0000000001
|
|||
[], [1], [1, 2, 3], ["1", "2",], [1, "1", True, [1]], ...
|
||||
```
|
||||
|
||||
### [辞書リテラル(Dict Literal)](./11_dict.md)
|
||||
|
||||
```python
|
||||
{:}, {"one": 1}, {"one": 1, "two": 2}, {"1": 1, "2": 2}, {1: "1", 2: True, "three": [1]}, ...
|
||||
```
|
||||
|
||||
### [組リテラル(Tuple Literal)](./12_tuple.md)
|
||||
### [組リテラル(Tuple Literal)](./11_tuple.md)
|
||||
|
||||
```python
|
||||
(), (1, 2, 3), (1, "hello", True), ...
|
||||
```
|
||||
|
||||
### [辞書リテラル(Dict Literal)](./12_dict.md)
|
||||
|
||||
```python
|
||||
{:}, {"one": 1}, {"one": 1, "two": 2}, {"1": 1, "2": 2}, {1: "1", 2: True, "three": [1]}, ...
|
||||
```
|
||||
|
||||
### [レコードリテラル(Record Literal)](./13_record.md)
|
||||
|
||||
```python
|
||||
|
|
|
@ -20,7 +20,7 @@ JavaScriptのオブジェクトリテラルとの相違点は、文字列でア
|
|||
これは、値へのアクセスをコンパイル時に決定するためと、辞書とレコードが別物であるためといった理由があります。つまり、`{"name": "John"}`はDict,`{name = "John"}`はレコードです。
|
||||
では、辞書とレコードはどう使い分ければいいのでしょうか。
|
||||
一般的にはレコードの使用を推奨します。レコードには、コンパイル時に要素が存在するかチェックされる、 __可視性(visibility)__ を指定できるなどのメリットがあります。
|
||||
可視性の指定は、Java言語などでみられるpublic/privateの指定に相当します。詳しくは[可視性](./15_visibility.md)を参照してください。
|
||||
可視性の指定は、Java言語などでみられるpublic/privateの指定に相当します。詳しくは[可視性](./19_visibility.md)を参照してください。
|
||||
|
||||
```python
|
||||
a = {x = 1; .y = x + 1}
|
||||
|
|
|
@ -51,7 +51,7 @@ log s2, s1 # !"HELLO hello"
|
|||
不変オブジェクトは複数の場所から参照できることを利用して、可変オブジェクトを不変オブジェクトに変換します。
|
||||
これを凍結といいます。凍結は可変配列からイテレータを作るときなどで使われます。
|
||||
可変配列からは直接イテレータを作ることができないので、不変配列に変換します。
|
||||
配列を壊したくない場合は、[`.freeze_map`メソッド](./type/mut.md)等を使います。
|
||||
配列を壊したくない場合は、[`.freeze_map`メソッド](./type/18_mut.md)等を使います。
|
||||
|
||||
```python
|
||||
# イテレータが出す値の合計を計算する
|
||||
|
|
|
@ -103,7 +103,7 @@ C.
|
|||
オブジェクトからは、クラスメソッドの他にパッチメソッドも使用可能です。
|
||||
Ergではクラスメソッドを追加したりはできませんが、[パッチ](./07_patch.md)で拡張可能です。
|
||||
|
||||
既存のクラスを継承することも出来ます([Inheritable](./../27_decorator.md/#inheritable)クラスの場合)。
|
||||
既存のクラスを継承することも出来ます([Inheritable](../29_decorator.md#inheritable)クラスの場合)。
|
||||
`Inherit`は継承を意味します。左辺の型を派生クラス、右辺の`Inherit`の引数型を基底クラスと言います。
|
||||
|
||||
```python
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
Refinement type(篩型、ふるいがた)は、述語式によって制約付けられた型です。列挙型や区間型は篩型の一種です。
|
||||
|
||||
篩型の標準形は`{Elem: Type | (Pred)*}`です。これは、`Pred`を満たす`Elem`を要素とする型である、という意味です。
|
||||
篩型に使えるのは[Const型](./advanced/const.md)のみです。
|
||||
篩型に使えるのは[Const型]のみです。
|
||||
|
||||
```python
|
||||
Nat = 0.._
|
||||
|
|
|
@ -33,7 +33,7 @@ tuple_map f: (|T: Type| T -> T), tup: (Int, Str) = (f(tup.0), f(tup.1))
|
|||
assert tuple_map(i -> i * 2, (1, "a")) == (2, "aa")
|
||||
```
|
||||
|
||||
`{(型) | (型変数のリスト)}`という形式の型を全称型といった(詳しくは[全称型](./../quantified.md)を参照)。
|
||||
`{(型) | (型変数のリスト)}`という形式の型を全称型といった(詳しくは[全称型](../15_quantified.md)を参照)。
|
||||
いままで見てきた`id`関数は、典型的な全称関数=多相関数である。
|
||||
|
||||
```python
|
||||
|
|
|
@ -1,2 +1,17 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/tools/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [build](./build.md)
|
||||
|
||||
## [env](./env.md)
|
||||
|
||||
## [fmt](./fmt.md)
|
||||
|
||||
## [install](./install.md)
|
||||
|
||||
## [pack](./pack.md)
|
||||
|
||||
## [repl](./repl.md)
|
||||
|
||||
## [test](./test.md)
|
|
@ -1,2 +1,15 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [consts](./consts.md)
|
||||
|
||||
## [funcs](./funcs.md)
|
||||
|
||||
## [operations](./operators.md)
|
||||
|
||||
## [procs](./procs.md)
|
||||
|
||||
## [special](./special.md)
|
||||
|
||||
## [types](./types.md)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
## 重载(临时多态性)
|
||||
|
||||
被放弃了,因为它可以用参数+子类型多态来代替,并且与Python的语义不兼容。 有关详细信息,请参阅 [overload](../syntax/type/overloading.md) 文章。
|
||||
被放弃了,因为它可以用参数+子类型多态来代替,并且与Python的语义不兼容。 有关详细信息,请参阅 [overload](../syntax/type/advanced/overloading.md) 文章。
|
||||
|
||||
## 具有显式生命周期的所有权系统
|
||||
|
||||
|
|
|
@ -1,2 +1,31 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/compiler/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [abandoned](./abandoned.md)
|
||||
|
||||
## [architecture](./architecture.md)
|
||||
|
||||
## [error](./errors.md)
|
||||
|
||||
## [hir](./hir.md)
|
||||
|
||||
## [inference](./inference.md)
|
||||
|
||||
## [overview](./overview.md)
|
||||
|
||||
## [parsing](./parsing.md)
|
||||
|
||||
## [refinement_subtyping](./refinement_subtyping.md)
|
||||
|
||||
## [TODO_hint](./TODO_hint.md)
|
||||
|
||||
## [TODO_recov_suggest](./TODO_recov_suggest.md)
|
||||
|
||||
## [TODO_warn](./TODO_warn.md)
|
||||
|
||||
## [trait_method_resolving](./trait_method_resolving.md)
|
||||
|
||||
## [transpile](./transpile.md)
|
||||
|
||||
## [type_var_normalization.](type_var_normalization.md)
|
|
@ -65,7 +65,7 @@ Erg 的类型推断主要使用 Hindley-Milner 类型推断算法(尽管已经
|
|||
|
||||
## 类型变量的实现
|
||||
|
||||
类型变量最初在 [ty.rs](../../src/common/ty.rs) 的 `Type` 中表示如下。它现在以不同的方式实现,但本质上是相同的想法,所以我将以更天真的方式考虑这种实现。
|
||||
类型变量最初在 [ty.rs] 的 `Type` 中表示如下。它现在以不同的方式实现,但本质上是相同的想法,所以我将以更天真的方式考虑这种实现。
|
||||
`RcCell<T>` 是 `Rc<RefCell<T>>` 的包装类型。
|
||||
|
||||
```rust
|
||||
|
@ -98,7 +98,7 @@ pub enum Type {
|
|||
让我们将未绑定类型变量 `?T` 泛化为 `gen` 的操作表示。令生成的广义类型变量为 `|T: Type| T`。
|
||||
在类型论中,量化类型,例如多相关类型 `α->α`,通过在它们前面加上 `∀α.` 来区分(像 ∀ 这样的符号称为(通用)量词。)。
|
||||
这样的表示(例如`∀α.α->α`)称为类型方案。 Erg 中的类型方案表示为 `|T: Type| T -> T`。
|
||||
类型方案通常不被认为是一流的类型。以这种方式配置类型系统可以防止类型推断起作用。但是,在Erg中,在一定条件下可以算是一流的类型。有关详细信息,请参阅 [rank2 类型](../syntax/type/advanced/rank2type.md)。
|
||||
类型方案通常不被认为是一流的类型。以这种方式配置类型系统可以防止类型推断起作用。但是,在Erg中,在一定条件下可以算是一流的类型。有关详细信息,请参阅 [rank2 类型](../syntax/type/advanced/_rank2type.md)。
|
||||
|
||||
现在,当在使用它的类型推断(例如,`id 1`,`id True`)中使用获得的类型方案(例如`'T -> 'T(id's type scheme)`)时,必须释放generalize。这种逆变换称为 __instantiation__。我们将调用操作`inst`。
|
||||
|
||||
|
@ -114,7 +114,7 @@ inst 'T = ?T (?T ∉ Γ)
|
|||
此外,如果表达式是调用,则获取返回类型的操作表示为 `subst_call_ret`。 第一个参数是参数类型列表,第二个参数是要分配的类型。
|
||||
|
||||
类型替换规则 `{?T --> X}` 意味着将 `?T` 和 `X` 重写为相同类型。 此操作称为 __Unification__。 `X` 也可以是类型变量。
|
||||
[单独部分](./unification.md) 中描述了详细的统一算法。 我们将统一操作表示为"统一"。
|
||||
[单独部分] 中描述了详细的统一算法。 我们将统一操作表示为"统一"。
|
||||
|
||||
```python
|
||||
unify(?T, Int) == Ok(()) # ?T == (Int)
|
||||
|
|
|
@ -1,2 +1,17 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/dev_guide/index.md&commit_hash=7d43acdf0e2b71528b038b9a8e70be6c93831f96)
|
||||
|
||||
## [branches](./branches.md)
|
||||
|
||||
## [build_features](./build_features.md)
|
||||
|
||||
## [directories](./directories.md)
|
||||
|
||||
## [doc_guideline](./doc_guideline.md)
|
||||
|
||||
## [env](./env.md)
|
||||
|
||||
## [i18n_messages](./i18n_messages.md)
|
||||
|
||||
## [rust_code_guideline](./rust_code_guideline.md)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
此常见问题解答适用于一般 Erg 初学者。
|
||||
对于个别(常见)技术问题,请参阅 [此处](./faq_technical.md) 了解个别(常见)技术问题,以及
|
||||
[这里](./dev_guide/faq_syntax.md) 了解更多信息。
|
||||
[这里](./faq_syntax.md) 了解更多信息。
|
||||
|
||||
## Erg 是 Python 兼容语言是什么意思?
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
__注意__: Erg 引入所有权系统的动机不是像 Rust 那样"不依赖 GC 的内存管理"。
|
||||
Erg 所有权系统的目标是"可变状态的本地化"。 Erg 有一个附属于可变对象的所有权概念。
|
||||
这是因为共享可变状态容易出现错误,甚至违反类型安全(参见 [此处](../syntax/type/advanced/shared.md#共享参考))。这是一个判断决定。
|
||||
这是因为共享可变状态容易出现错误,甚至违反类型安全(参见 [此处](./syntax/type/advanced/shared.md#共享参考))。这是一个判断决定。
|
||||
|
||||
## 为什么类型参数要大括号 || 而不是 <> 或 []?
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
本节回答有关使用 Erg 语言的技术问题。换句话说,它包含以 What 或 Which 开头的问题,以及可以用 Yes/No 回答的问题。
|
||||
|
||||
有关如何确定语法的更多信息,请参阅 [此处](./dev_guide/faq_syntax.md) 了解基础语法决策,以及 [此处](./dev_guide/../faq_general.md)。
|
||||
有关如何确定语法的更多信息,请参阅 [此处](./faq_syntax.md) 了解基础语法决策,以及 [此处](./faq_general.md)。
|
||||
|
||||
## Erg 中有异常机制吗?
|
||||
|
||||
答:不会。Erg 使用 `Result` 类型代替。请参阅 [此处](./dev_guide/faq_syntax.md) 了解 Erg 没有异常机制的原因。
|
||||
答:不会。Erg 使用 `Result` 类型代替。请参阅 [此处](./faq_syntax.md) 了解 Erg 没有异常机制的原因。
|
||||
|
||||
## Erg 是否有与 TypeScript 的 `Any` 等价的类型?
|
||||
|
||||
|
|
|
@ -1,2 +1,9 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/python/index.md&commit_hash=9f6a4a43fcf7e4f58cabe6e5a7546820fd9f5ff4)
|
||||
|
||||
## [bytecode_instructions](./bytecode_instructions.md)
|
||||
|
||||
## [bytecode_specification](./bytecode_specification.md)
|
||||
|
||||
## [class_system](./class_system.md)
|
|
@ -5,7 +5,7 @@
|
|||
> __Warning__:本文档不完整。 它未经校对(样式、正确链接、误译等)。 此外,Erg 的语法可能在版本 0.* 期间发生破坏性更改,并且文档可能没有相应更新。 请事先了解这一点。
|
||||
> 如果您在本文档中发现任何错误,请报告至 [此处的表单](https://forms.gle/HtLYRfYzWCAaeTGb6) 或 [GitHub repo](https://github.com/mtshiba/TheErgBook/issues/new )。 我们将不胜感激您的建议。
|
||||
|
||||
本文档描述 Erg 的基本语法。 [标准 API](./API/index.md) 和 [Erg 贡献者的内部文档](./dev_guide/index.md) 位于另一个目录中。
|
||||
本文档描述 Erg 的基本语法。 [标准 API](../API/index.md) 和 [Erg 贡献者的内部文档](../dev_guide/index.md) 位于另一个目录中。
|
||||
|
||||
## 你好,世界!
|
||||
|
||||
|
|
|
@ -67,18 +67,18 @@ assert 1e-10 == 0.0000000001
|
|||
[], [1], [1, 2, 3], ["1", "2",], [1, "1", True, [1]], ...
|
||||
```
|
||||
|
||||
### [字典字面量](./11_dict.md)
|
||||
|
||||
```python
|
||||
{:}, {"one": 1}, {"one": 1, "two": 2}, {"1": 1, "2": 2}, {1: "1", 2: True, "three": [1]}, ...
|
||||
```
|
||||
|
||||
### [元组字面量](./12_tuple.md)
|
||||
### [元组字面量](./11_tuple.md)
|
||||
|
||||
```python
|
||||
(), (1, 2, 3), (1, "hello", True), ...
|
||||
```
|
||||
|
||||
### [字典字面量](./12_dict.md)
|
||||
|
||||
```python
|
||||
{:}, {"one": 1}, {"one": 1, "two": 2}, {"1": 1, "2": 2}, {1: "1", 2: True, "three": [1]}, ...
|
||||
```
|
||||
|
||||
### [Record 字面量](./13_record.md)
|
||||
|
||||
```python
|
||||
|
|
|
@ -20,7 +20,7 @@ john["name"] # 错误:john 不可订阅
|
|||
这是因为对值的访问是在编译时确定的,而且字典和记录是不同的东西。 换句话说,`{"name": "John"}` 是一个字典,`{name = "John"}` 是一个记录。
|
||||
那么我们应该如何使用字典和记录呢?
|
||||
一般来说,我们建议使用记录。 记录具有在编译时检查元素是否存在以及能够指定 __visibility_ 的优点。
|
||||
指定可见性等同于在 Java 和其他语言中指定公共/私有。 有关详细信息,请参阅 [可见性](./15_visibility.md) 了解详细信息。
|
||||
指定可见性等同于在 Java 和其他语言中指定公共/私有。 有关详细信息,请参阅 [可见性](./19_visibility.md) 了解详细信息。
|
||||
|
||||
```python
|
||||
a = {x = 1; .y = x + 1}
|
||||
|
|
|
@ -51,7 +51,7 @@ log s2, s1 # !"HELLO hello"
|
|||
我们利用了不可变对象可以从多个位置引用的事实,并将可变对象转换为不可变对象。
|
||||
这称为冻结。 例如,在从可变数组创建迭代器时会使用冻结。
|
||||
由于您不能直接从可变数组创建迭代器,请将其转换为不可变数组。
|
||||
如果您不想破坏数组,请使用 [`.freeze_map` 方法](./type/mut.md)。
|
||||
如果您不想破坏数组,请使用 [`.freeze_map` 方法](./type/18_mut.md)。
|
||||
|
||||
```python
|
||||
# 计算迭代器产生的值的总和
|
||||
|
|
|
@ -101,7 +101,7 @@ C.i = 1 # 属性错误:`.i` 已在实例字段中定义
|
|||
对象可以使用补丁方法以及类方法。
|
||||
Erg 不允许您添加类方法,但您可以使用 [patch](./07_patch.md) 来扩展类。
|
||||
|
||||
您还可以从现有类([Inheritable](./../27_decorator.md/#inheritable) 类)继承。
|
||||
您还可以从现有类([Inheritable](../29_decorator.md#可继承) 类)继承。
|
||||
您可以使用 `Inherit` 创建一个继承类。 左侧的类型称为派生类,右侧的"继承"的参数类型称为基类(继承类)。
|
||||
|
||||
```python
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
细化类型是受谓词表达式约束的类型。 枚举类型和区间类型是细化类型的语法糖。
|
||||
|
||||
细化类型的标准形式是`{Elem: Type | (预)*}`。 这意味着该类型是其元素为满足 `Pred` 的 `Elem` 的类型。
|
||||
可用于筛选类型的类型仅为 [Const type](./advanced/const.md)。
|
||||
可用于筛选类型的类型仅为 [Const type]。
|
||||
|
||||
```python
|
||||
Nat = 0.. _
|
||||
|
|
|
@ -33,7 +33,7 @@ tuple_map f: (|T: Type| T -> T), tup: (Int, Str) = (f(tup.0), f(tup.1))
|
|||
assert tuple_map(i -> i * 2, (1, "a")) == (2, "aa")
|
||||
```
|
||||
|
||||
`{(type) | 形式的类型 (类型变量列表)}` 被称为通用类型(详见[通用类型](./../quantified.md))。
|
||||
`{(type) | 形式的类型 (类型变量列表)}` 被称为通用类型(详见[通用类型](../15_quantified.md))。
|
||||
目前我们看到的`id`函数是一个典型的通用函数=多相关函数。
|
||||
|
||||
```python
|
||||
|
|
|
@ -1,2 +1,17 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/tools/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [build](./build.md)
|
||||
|
||||
## [env](./env.md)
|
||||
|
||||
## [fmt](./fmt.md)
|
||||
|
||||
## [install](./install.md)
|
||||
|
||||
## [pack](./pack.md)
|
||||
|
||||
## [repl](./repl.md)
|
||||
|
||||
## [test](./test.md)
|
|
@ -1,2 +1,15 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [consts](./consts.md)
|
||||
|
||||
## [funcs](./funcs.md)
|
||||
|
||||
## [operations](./operators.md)
|
||||
|
||||
## [procs](./procs.md)
|
||||
|
||||
## [special](./special.md)
|
||||
|
||||
## [types](./types.md)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
## 重載(臨時多態性)
|
||||
|
||||
被放棄了,因為它可以用參數+子類型多態來代替,并且與Python的語義不兼容。 有關詳細信息,請參閱 [overload](../syntax/type/overloading.md) 文章。
|
||||
被放棄了,因為它可以用參數+子類型多態來代替,并且與Python的語義不兼容。 有關詳細信息,請參閱 [overload](../syntax/type/advanced/overloading.md) 文章。
|
||||
|
||||
## 具有顯式生命周期的所有權系統
|
||||
|
||||
|
|
|
@ -1,2 +1,31 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/compiler/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [abandoned](./abandoned.md)
|
||||
|
||||
## [architecture](./architecture.md)
|
||||
|
||||
## [error](./errors.md)
|
||||
|
||||
## [hir](./hir.md)
|
||||
|
||||
## [inference](./inference.md)
|
||||
|
||||
## [overview](./overview.md)
|
||||
|
||||
## [parsing](./parsing.md)
|
||||
|
||||
## [refinement_subtyping](./refinement_subtyping.md)
|
||||
|
||||
## [TODO_hint](./TODO_hint.md)
|
||||
|
||||
## [TODO_recov_suggest](./TODO_recov_suggest.md)
|
||||
|
||||
## [TODO_warn](./TODO_warn.md)
|
||||
|
||||
## [trait_method_resolving](./trait_method_resolving.md)
|
||||
|
||||
## [transpile](./transpile.md)
|
||||
|
||||
## [type_var_normalization.](type_var_normalization.md)
|
|
@ -65,7 +65,7 @@ Erg 的類型推斷主要使用 Hindley-Milner 類型推斷算法(盡管已經
|
|||
|
||||
## 類型變量的實現
|
||||
|
||||
類型變量最初在 [ty.rs](../../src/common/ty.rs) 的 `Type` 中表示如下。它現在以不同的方式實現,但本質上是相同的想法,所以我將以更天真的方式考慮這種實現。
|
||||
類型變量最初在 [ty.rs] 的 `Type` 中表示如下。它現在以不同的方式實現,但本質上是相同的想法,所以我將以更天真的方式考慮這種實現。
|
||||
`RcCell<T>` 是 `Rc<RefCell<T>>` 的包裝類型。
|
||||
|
||||
```rust
|
||||
|
@ -98,7 +98,7 @@ pub enum Type {
|
|||
讓我們將未綁定類型變量 `?T` 泛化為 `gen` 的操作表示。令生成的廣義類型變量為 `|T: Type| T`。
|
||||
在類型論中,量化類型,例如多相關類型 `α->α`,通過在它們前面加上 `?α.` 來區分(像 ? 這樣的符號稱為(通用)量詞。)。
|
||||
這樣的表示(例如`?α.α->α`)稱為類型方案。 Erg 中的類型方案表示為 `|T: Type| T -> T`。
|
||||
類型方案通常不被認為是一流的類型。以這種方式配置類型系統可以防止類型推斷起作用。但是,在Erg中,在一定條件下可以算是一流的類型。有關詳細信息,請參閱 [rank2 類型](../syntax/type/advanced/rank2type.md)。
|
||||
類型方案通常不被認為是一流的類型。以這種方式配置類型系統可以防止類型推斷起作用。但是,在Erg中,在一定條件下可以算是一流的類型。有關詳細信息,請參閱 [rank2 類型](../syntax/type/advanced/_rank2type.md)。
|
||||
|
||||
現在,當在使用它的類型推斷(例如,`id 1`,`id True`)中使用獲得的類型方案(例如`'T -> 'T(id's type scheme)`)時,必須釋放generalize。這種逆變換稱為 __instantiation__。我們將調用操作`inst`。
|
||||
|
||||
|
@ -114,7 +114,7 @@ inst 'T = ?T (?T ? Γ)
|
|||
此外,如果表達式是調用,則獲取返回類型的操作表示為 `subst_call_ret`。 第一個參數是參數類型列表,第二個參數是要分配的類型。
|
||||
|
||||
類型替換規則 `{?T --> X}` 意味著將 `?T` 和 `X` 重寫為相同類型。 此操作稱為 __Unification__。 `X` 也可以是類型變量。
|
||||
[單獨部分](./unification.md) 中描述了詳細的統一算法。 我們將統一操作表示為"統一"。
|
||||
[單獨部分] 中描述了詳細的統一算法。 我們將統一操作表示為"統一"。
|
||||
|
||||
```python
|
||||
unify(?T, Int) == Ok(()) # ?T == (Int)
|
||||
|
|
|
@ -1,2 +1,17 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/dev_guide/index.md&commit_hash=7d43acdf0e2b71528b038b9a8e70be6c93831f96)
|
||||
|
||||
## [branches](./branches.md)
|
||||
|
||||
## [build_features](./build_features.md)
|
||||
|
||||
## [directories](./directories.md)
|
||||
|
||||
## [doc_guideline](./doc_guideline.md)
|
||||
|
||||
## [env](./env.md)
|
||||
|
||||
## [i18n_messages](./i18n_messages.md)
|
||||
|
||||
## [rust_code_guideline](./rust_code_guideline.md)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
此常見問題解答適用於一般 Erg 初學者。
|
||||
對於個別(常見)技術問題,請參閱 [此處](./faq_technical.md) 了解個別(常見)技術問題,以及
|
||||
[這裡](./dev_guide/faq_syntax.md) 了解更多信息。
|
||||
[這裡](./faq_syntax.md) 了解更多信息。
|
||||
|
||||
## Erg 是 Python 兼容語言是什么意思?
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
__注意__: Erg 引入所有權系統的動機不是像 Rust 那樣"不依賴 GC 的內存管理"。
|
||||
Erg 所有權系統的目標是"可變狀態的本地化"。 Erg 有一個附屬於可變對象的所有權概念。
|
||||
這是因為共享可變狀態容易出現錯誤,甚至違反類型安全(參見 [此處](../syntax/type/advanced/shared.md#共享參考))。這是一個判斷決定。
|
||||
這是因為共享可變狀態容易出現錯誤,甚至違反類型安全(參見 [此處](./syntax/type/advanced/shared.md#共享參考))。這是一個判斷決定。
|
||||
|
||||
## 為什麼類型參數要大括號 || 而不是 <> 或 []?
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
本節回答有關使用 Erg 語言的技術問題。換句話說,它包含以 What 或 Which 開頭的問題,以及可以用 Yes/No 回答的問題。
|
||||
|
||||
有關如何確定語法的更多信息,請參閱 [此處](./dev_guide/faq_syntax.md) 了解基礎語法決策,以及 [此處](./dev_guide/../faq_general.md)。
|
||||
有關如何確定語法的更多信息,請參閱 [此處](./faq_syntax.md) 了解基礎語法決策,以及 [此處](./faq_general.md)。
|
||||
|
||||
## Erg 中有異常機制嗎?
|
||||
|
||||
答:不會。Erg 使用 `Result` 類型代替。請參閱 [此處](./dev_guide/faq_syntax.md) 了解 Erg 沒有異常機制的原因。
|
||||
答:不會。Erg 使用 `Result` 類型代替。請參閱 [此處](./faq_syntax.md) 了解 Erg 沒有異常機制的原因。
|
||||
|
||||
## Erg 是否有與 TypeScript 的 `Any` 等價的類型?
|
||||
|
||||
|
|
|
@ -1,2 +1,9 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/python/index.md&commit_hash=9f6a4a43fcf7e4f58cabe6e5a7546820fd9f5ff4)
|
||||
|
||||
## [bytecode_instructions](./bytecode_instructions.md)
|
||||
|
||||
## [bytecode_specification](./bytecode_specification.md)
|
||||
|
||||
## [class_system](./class_system.md)
|
|
@ -5,7 +5,7 @@
|
|||
> __Warning__:本文檔不完整。 它未經校對(樣式、正確鏈接、誤譯等)。 此外,Erg 的語法可能在版本 0.* 期間發生破壞性更改,并且文檔可能沒有相應更新。 請事先了解這一點。
|
||||
> 如果您在本文檔中發現任何錯誤,請報告至 [此處的表單](https://forms.gle/HtLYRfYzWCAaeTGb6) 或 [GitHub repo](https://github.com/mtshiba/TheErgBook/issues/new )。 我們將不勝感激您的建議。
|
||||
|
||||
本文檔描述 Erg 的基本語法。 [標準 API](./API/index.md) 和 [Erg 貢獻者的內部文檔](./dev_guide/index.md) 位于另一個目錄中。
|
||||
本文檔描述 Erg 的基本語法。 [標準 API](../API/index.md) 和 [Erg 貢獻者的內部文檔](../dev_guide/index.md) 位于另一個目錄中。
|
||||
|
||||
## 你好,世界!
|
||||
|
||||
|
|
|
@ -67,18 +67,18 @@ assert 1e-10 == 0.0000000001
|
|||
[], [1], [1, 2, 3], ["1", "2",], [1, "1", True, [1]], ...
|
||||
```
|
||||
|
||||
### [字典字面量](./11_dict.md)
|
||||
|
||||
```python
|
||||
{:}, {"one": 1}, {"one": 1, "two": 2}, {"1": 1, "2": 2}, {1: "1", 2: True, "three": [1]}, ...
|
||||
```
|
||||
|
||||
### [元組字面量](./12_tuple.md)
|
||||
### [元組字面量](./11_tuple.md)
|
||||
|
||||
```python
|
||||
(), (1, 2, 3), (1, "hello", True), ...
|
||||
```
|
||||
|
||||
### [字典字面量](./12_dict.md)
|
||||
|
||||
```python
|
||||
{:}, {"one": 1}, {"one": 1, "two": 2}, {"1": 1, "2": 2}, {1: "1", 2: True, "three": [1]}, ...
|
||||
```
|
||||
|
||||
### [Record 字面量](./13_record.md)
|
||||
|
||||
```python
|
||||
|
|
|
@ -20,7 +20,7 @@ john["name"] # 錯誤:john 不可訂閱
|
|||
這是因為對值的訪問是在編譯時確定的,而且字典和記錄是不同的東西。 換句話說,`{"name": "John"}` 是一個字典,`{name = "John"}` 是一個記錄。
|
||||
那么我們應該如何使用字典和記錄呢?
|
||||
一般來說,我們建議使用記錄。 記錄具有在編譯時檢查元素是否存在以及能夠指定 __visibility_ 的優點。
|
||||
指定可見性等同于在 Java 和其他語言中指定公共/私有。 有關詳細信息,請參閱 [可見性](./15_visibility.md) 了解詳細信息。
|
||||
指定可見性等同于在 Java 和其他語言中指定公共/私有。 有關詳細信息,請參閱 [可見性](./19_visibility.md) 了解詳細信息。
|
||||
|
||||
```python
|
||||
a = {x = 1; .y = x + 1}
|
||||
|
|
|
@ -51,7 +51,7 @@ log s2, s1 # !"HELLO hello"
|
|||
我們利用了不可變對象可以從多個位置引用的事實,并將可變對象轉換為不可變對象。
|
||||
這稱為凍結。 例如,在從可變數組創建迭代器時會使用凍結。
|
||||
由于您不能直接從可變數組創建迭代器,請將其轉換為不可變數組。
|
||||
如果您不想破壞數組,請使用 [`.freeze_map` 方法](./type/mut.md)。
|
||||
如果您不想破壞數組,請使用 [`.freeze_map` 方法](./type/18_mut.md)。
|
||||
|
||||
```python
|
||||
# 計算迭代器產生的值的總和
|
||||
|
|
|
@ -101,7 +101,7 @@ C.i = 1 # 屬性錯誤:`.i` 已在實例字段中定義
|
|||
對象可以使用補丁方法以及類方法。
|
||||
Erg 不允許您添加類方法,但您可以使用 [patch](./07_patch.md) 來擴展類。
|
||||
|
||||
您還可以從現有類([Inheritable](./../27_decorator.md/#inheritable) 類)繼承。
|
||||
您還可以從現有類([Inheritable](../29_decorator.md#可繼承) 類)繼承。
|
||||
您可以使用 `Inherit` 創建一個繼承類。左側的類型稱為派生類,右側的"繼承"的參數類型稱為基類(繼承類)。
|
||||
|
||||
```python
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
細化類型是受謂詞表達式約束的類型。 枚舉類型和區間類型是細化類型的語法糖。
|
||||
|
||||
細化類型的標準形式是`{Elem: Type | (預)*}`。 這意味著該類型是其元素為滿足 `Pred` 的 `Elem` 的類型。
|
||||
可用于篩選類型的類型僅為 [Const type](./advanced/const.md)。
|
||||
可用于篩選類型的類型僅為 [Const type]。
|
||||
|
||||
```python
|
||||
Nat = 0.. _
|
||||
|
|
|
@ -33,7 +33,7 @@ tuple_map f: (|T: Type| T -> T), tup: (Int, Str) = (f(tup.0), f(tup.1))
|
|||
assert tuple_map(i -> i * 2, (1, "a")) == (2, "aa")
|
||||
```
|
||||
|
||||
`{(type) | 形式的類型 (類型變量列表)}` 被稱為通用類型(詳見[通用類型](./../quantified.md))。
|
||||
`{(type) | 形式的類型 (類型變量列表)}` 被稱為通用類型(詳見[通用類型](../15_quantified.md))。
|
||||
目前我們看到的`id`函數是一個典型的通用函數=多相關函數。
|
||||
|
||||
```python
|
||||
|
|
|
@ -1,2 +1,17 @@
|
|||
# Index
|
||||
|
||||
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/tools/index.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
|
||||
|
||||
## [build](./build.md)
|
||||
|
||||
## [env](./env.md)
|
||||
|
||||
## [fmt](./fmt.md)
|
||||
|
||||
## [install](./install.md)
|
||||
|
||||
## [pack](./pack.md)
|
||||
|
||||
## [repl](./repl.md)
|
||||
|
||||
## [test](./test.md)
|
Loading…
Add table
Add a link
Reference in a new issue