Skip to content
This repository was archived by the owner on Jan 5, 2025. It is now read-only.

Commit 75dd310

Browse files
committed
Monad_Zoos翻訳 (#41)
* 翻訳開始 * Combined翻訳完了 * Except翻訳完了 * Id翻訳完了 * Option翻訳完了 * State翻訳完了
1 parent b70a96d commit 75dd310

File tree

7 files changed

+174
-5
lines changed

7 files changed

+174
-5
lines changed

GLOSSARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
| parse | パース | |
194194
| parser | パーサ | |
195195
| pattern matching | パターンマッチ | |
196+
| phantom type | 幽霊型 | |
196197
| polymorphic | 多相 | |
197198
| precedence | 優先順位 | 構文解析・演算子等の優先具合を指す |
198199
| predicate | 述語 | |

Manual/Monads/Zoo/Combined.lean

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,26 @@ set_option pp.rawOnError true
1919

2020
set_option linter.unusedVariables false
2121

22+
/-
2223
#doc (Manual) "Combined Error and State Monads" =>
24+
-/
25+
#doc (Manual) "エラーと状態モナドの結合(Combined Error and State Monads)" =>
2326

2427
```lean (show := false)
2528
variable (ε : Type u) (σ σ' : Type u) (α : Type u)
2629
```
2730

31+
:::comment
2832
The {name}`EStateM` monad has both exceptions and mutable state.
2933
{lean}`EStateM ε σ α` is logically equivalent to {lean}`ExceptT ε (StateM σ) α`.
3034
While {lean}`ExceptT ε (StateM σ)` evaluates to the type {lean}`σ → Except ε α × σ`, the type {lean}`EStateM ε σ α` evaluates to {lean}`σ → EStateM.Result ε σ α`.
3135
{name}`EStateM.Result` is an inductive type that's very similar to {name}`Except`, except both constructors have an additional field for the state.
3236
In compiled code, this representation removes one level of indirection from each monadic bind.
3337

38+
:::
39+
40+
{name}`EStateM` モナドは例外と可変状態の両方を持ちます。 {lean}`EStateM ε σ α` は {lean}`ExceptT ε (StateM σ) α` と論理的に等価です。 {lean}`ExceptT ε (StateM σ)` が {lean}`σ → Except ε α × σ` 型に評価されるのに対して、 {lean}`EStateM ε σ α` は {lean}`σ → EStateM.Result ε σ α` 型に評価されます。 {name}`EStateM.Result` は {name}`Except` とよく似た帰納型ですが、どちらのコンストラクタにも状態を表すフィールドが追加されています。コンパイルされたコードでは、この表現は各モナドの bind から1段階インダイレクションを取り除きます。
41+
3442
```lean (show := false)
3543
/-- info: σ → Except ε α × σ -/
3644
#guard_msgs in
@@ -53,28 +61,58 @@ In compiled code, this representation removes one level of indirection from each
5361

5462
{docstring EStateM.fromStateM}
5563

64+
:::comment
5665
# State Rollback
66+
:::
5767

68+
# 状態のロールバック(State Rollback)
69+
70+
71+
:::comment
5872
Composing {name}`StateT` and {name}`ExceptT` in different orders causes exceptions to interact differently with state.
5973
In one ordering, state changes are rolled back when exceptions are caught; in the other, they persist.
6074
The latter option matches the semantics of most imperative programming languages, but the former is very useful for search-based problems.
6175
Often, some but not all state should be rolled back; this can be achieved by “sandwiching” {name}`ExceptT` between two separate uses of {name}`StateT`.
6276

63-
To avoid yet another layer of indirection via the use of {lean}`StateT σ (EStateM ε σ') α`, {name}`EStateM` offers the {name}`EStateM.Backtrackable` {tech}[型クラス]type class.
77+
:::
78+
79+
{name}`StateT` と {name}`ExceptT` を異なる順序で合成すると例外と状態の相互作用は異なるものになります。片方の順序では、例外が捕捉された時に状態の変更がロールバックされ、もう一方では状態が持続します。後者のオプションはほとんどの命令型プログラミング言語のセマンティックスに一致しますが、前者は検索ベースの問題に対して非常に便利です。またしばしば、すべてではなく一部の状態だけがロールバックされるべき場合もあります;これは {name}`ExceptT`2つの {name}`StateT` で「サンドイッチ」することで実現できます。
80+
81+
:::comment
82+
To avoid yet another layer of indirection via the use of {lean}`StateT σ (EStateM ε σ') α`, {name}`EStateM` offers the {name}`EStateM.Backtrackable` {tech}[type class].
6483
This class specifies some part of the state that can be saved and restored.
6584
{name}`EStateM` then arranges for the saving and restoring to take place around error handling.
6685

86+
:::
87+
88+
{lean}`StateT σ (EStateM ε σ') α` の使用によるさらに別のレイヤーからのインダイレクトを避けるために、 {name}`EStateM` は {name}`EStateM.Backtrackable` {tech}[型クラス] を提供します。このクラスは保存と復元が可能な状態の一部を指定します。 {name}`EStateM` はエラー処理を中心に保存と復元が行われるよう調整します。
89+
6790
{docstring EStateM.Backtrackable}
6891

92+
:::comment
6993
There is a universally-applicable instance of {name EStateM.Backtrackable}`Backtrackable` that neither saves nor restores anything.
7094
Because instance synthesis chooses the most recent instance first, the universal instance is used only if no other instance has been defined.
7195

96+
:::
97+
98+
{name EStateM.Backtrackable}`Backtrackable` には普遍的に適用可能なインスタンスがありますが、これは何も保存も復元もしません。インスタンス統合は最新のインスタンスを最初に選択するため、他のインスタンスが定義されていない場合にのみこの普遍的なインスタンスが使用されます。
99+
72100
{docstring EStateM.nonBacktrackable}
73101

102+
:::comment
74103
# Implementations
104+
:::
75105

106+
# 実装(Implementations)
107+
108+
109+
:::comment
76110
These functions are typically not called directly, but rather are accessed through their corresponding type classes.
77111

112+
:::
113+
114+
これらの関数は通常、直接呼び出されることはなく、対応する型クラスを通じてアクセスされます。
115+
78116
{docstring EStateM.map}
79117

80118
{docstring EStateM.pure}

Manual/Monads/Zoo/Except.lean

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,30 @@ set_option pp.rawOnError true
1919

2020
set_option linter.unusedVariables false
2121

22+
/-
2223
#doc (Manual) "Exceptions" =>
24+
-/
25+
#doc (Manual) "例外(Exceptions)" =>
2326
%%%
2427
tag := "exception-monads"
2528
%%%
2629

30+
:::comment
2731
Exception monads describe computations that terminate early (fail).
2832
Failing computations provide their caller with an _exception_ value that describes _why_ they failed.
2933
In other words, computations either return a value or an exception.
3034
The inductive type {name}`Except` captures this pattern, and is itself a monad.
3135

36+
:::
37+
38+
例外モナドは早期に終了(失敗)する計算を記述します。失敗した計算は、 _なぜ_ 失敗したかを示す _例外_ 値を呼び出し元に提供します。言い換えると、計算は値か例外を返します。帰納型 {name}`Except` はこのパターンを捕捉しており、それ自体がモナドです。
39+
40+
:::comment
3241
# Exceptions
42+
:::
43+
44+
# 例外(Exceptions)
45+
3346

3447
{docstring Except}
3548

@@ -52,7 +65,12 @@ The inductive type {name}`Except` captures this pattern, and is itself a monad.
5265
{docstring Except.toBool}
5366

5467

68+
:::comment
5569
# Type Class
70+
:::
71+
72+
# 型クラス(Type Class)
73+
5674

5775
{docstring MonadExcept}
5876

@@ -68,11 +86,21 @@ The inductive type {name}`Except` captures this pattern, and is itself a monad.
6886

6987
{docstring tryCatchThe}
7088

89+
:::comment
7190
# “Finally” Computations
91+
:::
92+
93+
# 「finally」の計算(“Finally” Computations)
94+
7295

7396
{docstring MonadFinally}
7497

98+
:::comment
7599
# Transformer
100+
:::
101+
102+
# 変換子(Transformer)
103+
76104

77105
{docstring ExceptT}
78106

@@ -95,7 +123,12 @@ The inductive type {name}`Except` captures this pattern, and is itself a monad.
95123
{docstring ExceptT.adapt}
96124

97125

126+
:::comment
98127
# Exception Monads in Continuation Passing Style
128+
:::
129+
130+
# 継続渡しスタイルの例外モナド(Exception Monads in Continuation Passing Style)
131+
99132

100133
```lean (show := false)
101134
universe u
@@ -104,12 +137,17 @@ variable (ε : Type u)
104137
variable {m : Type u → Type v}
105138
```
106139

140+
:::comment
107141
Continuation-passing-style exception monads represent potentially-failing computations as functions that take success and failure continuations, both of which return the same type, returning that type.
108142
They must work for _any_ return type.
109143
An example of such a type is {lean}`(β : Type u) → (α → β) → (ε → β) → β`.
110144
{lean}`ExceptCpsT` is a transformer that can be applied to any monad, so {lean}`ExceptCpsT ε m α` is actually defined as {lean}`(β : Type u) → (α → m β) → (ε → m β) → m β`.
111145
Exception monads in continuation passing style have different performance characteristics than {name}`Except`-based state monads; for some applications, it may be worth benchmarking them.
112146

147+
:::
148+
149+
継続渡しスタイルの例外モナドは、失敗する可能性のある計算を、成功と失敗を取る関数として表します。この継続はどちらも同じ型を返し、この関数はその型を返します。例外モナドは _どのような_ 戻り値の型でも動作しなければなりません。このような型の例は {lean}`(β : Type u) → (α → β) → (ε → β) → β` です。 {lean}`ExceptCpsT` は任意のモナドに適用できる変換子であるため、 {lean}`ExceptCpsT ε m α` は実際には {lean}`(β : Type u) → (α → m β) → (ε → m β) → m β` と定義されています。継続渡しスタイルの例外モナドは、 {name}`Except` ベースの状態モナドとは異なるパフォーマンス特性を持ちます;アプリケーションによってはベンチマークを取る価値があるかもしれません。
150+
113151
```lean (show := false)
114152
/-- info: (β : Type u) → (α → m β) → (ε → m β) → m β -/
115153
#guard_msgs in

Manual/Monads/Zoo/Id.lean

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@ set_option pp.rawOnError true
1919

2020
set_option linter.unusedVariables false
2121

22+
/-
2223
#doc (Manual) "Identity" =>
24+
-/
25+
#doc (Manual) "恒等モナド(Identity)" =>
2326

27+
:::comment
2428
The identity monad {name}`Id` has no effects whatsoever.
2529
Both {name}`Id` and the corresponding implementation of {name}`pure` are the identity function, and {name}`bind` is reversed function application.
2630
The identity monad has two primary use cases:
2731
1. It can be the type of a {keywordOf Lean.Parser.Term.do}`do` block that implements a pure function with local effects.
2832
2. It can be placed at the bottom of a stack of monad transformers.
2933

34+
:::
35+
36+
恒等モナド {name}`Id` は何の作用も持ちません。 {name}`Id` と対応する {name}`pure` の実装はどちらも恒等関数であり、 {name}`bind` は関数適用を逆転させたものです。恒等モナドには主に2つの使用例があります:
37+
1. {keywordOf Lean.Parser.Term.do}`do` ブロックの型にして、局所的に作用を持つ純粋関数を実装することができます。
38+
2. モナド変換子のスタックの一番下に置くことができます。
39+
3040
```lean (show := false)
3141
-- Verify claims
3242
example : Id = id := rfl
@@ -39,8 +49,16 @@ example : (bind (m := Id)) = (fun (x : α) (f : α → Id β) => f x) := rfl
3949

4050
{docstring Id.run}
4151

42-
:::example "Local Effects with the Identity Monad"
52+
:::comment
53+
::example "Local Effects with the Identity Monad"
54+
:::
55+
::::example "恒等モナドによる局所的な作用"
56+
:::comment
4357
This code block implements a countdown procedure by using simulated local mutability in the identity monad.
58+
:::
59+
60+
このコードブロックは恒等モナドのシミュレートされた局所的な可変性を使ってカウントダウン処理を実装しています。
61+
4462
```lean (name := idDo)
4563
#eval Id.run do
4664
let mut xs := []
@@ -51,6 +69,6 @@ This code block implements a countdown procedure by using simulated local mutabi
5169
```leanOutput idDo
5270
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
5371
```
54-
:::
72+
::::
5573

5674
{docstring Id.hasBind}

Manual/Monads/Zoo/Option.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,24 @@ set_option pp.rawOnError true
1919

2020
set_option linter.unusedVariables false
2121

22+
/-
2223
#doc (Manual) "Option" =>
24+
-/
25+
#doc (Manual) "オプション(Option)" =>
2326
%%%
2427
tag := "option-monad"
2528
%%%
2629

30+
:::comment
2731
Ordinarily, {lean}`Option` is thought of as data, similarly to a nullable type.
2832
It can also be considered as a monad, and thus a way of performing computations.
2933
The {lean}`Option` monad and its transformer {lean}`OptionT` can be understood as describing computations that may terminate early, discarding the results.
3034
Callers can check for early termination and invoke a fallback if desired using {name}`OrElse.orElse` or by treating it as a {lean}`MonadExcept Unit`.
3135

36+
:::
37+
38+
通常、 {lean}`Option` は nullable 型と同じようなデータとして考えられます。また、モナド、つまり計算を実行する方法として考えることもできます。 {lean}`Option` モナドとその変換子 {lean}`OptionT` は、結果を破棄して早期に終了する可能性のある計算を記述するものとして理解することができます。呼び出し元は {name}`OrElse.orElse` を使用するか、 {lean}`MonadExcept Unit` として扱うことで早期終了をチェックし、必要に応じてフォールバックを呼び出すことができます。
39+
3240
{docstring OptionT}
3341

3442
{docstring OptionT.run}

Manual/Monads/Zoo/Reader.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ set_option pp.rawOnError true
1919

2020
set_option linter.unusedVariables false
2121

22+
/-
2223
#doc (Manual) "Reader" =>
24+
-/
25+
#doc (Manual) "リーダ(Reader)" =>
2326
%%%
2427
tag := "reader-monad"
2528
%%%

0 commit comments

Comments
 (0)