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

Commit 12e2833

Browse files
committed
Monad_Laws翻訳 (#37)
* 翻訳開始 * 翻訳完了
1 parent 4843a8a commit 12e2833

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

Manual/Monads/Laws.lean

Lines changed: 37 additions & 2 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) "Laws" =>
24+
-/
25+
#doc (Manual) "規則(Laws)" =>
2326
%%%
2427
tag := "monad-laws"
2528
%%%
@@ -38,40 +41,72 @@ axiom γ : Type u'
3841
axiom x : f α
3942
```
4043

41-
:::keepEnv
44+
::::keepEnv
4245
```lean (show := false)
4346
section F
4447
variable {f : Type u → Type v} [Functor f] {α β : Type u} {g : α → β} {h : β → γ} {x : f α}
4548
```
4649

50+
:::comment
4751
Having {name Functor.map}`map`, {name Pure.pure}`pure`, {name Seq.seq}`seq`, and {name Bind.bind}`bind` operators with the appropriate types is not really sufficient to have a functor, applicative functor, or monad.
4852
These operators must additionally satisfy certain axioms, which are often called the {deftech}_laws_ of the type class.
4953

54+
:::
55+
56+
演算子 {name Functor.map}`map` ・ {name Pure.pure}`pure` ・ {name Seq.seq}`seq` ・ {name Bind.bind}`bind` が適切な型を持っているだけでは、関手・アプリカティブ関手・モナドを持つには十分ではありません。これらの演算子はさらに特定の公理を満たす必要があり、これはしばしば型クラスの {deftech}_規則_ (law)と呼ばれます。
57+
58+
:::comment
5059
For a functor, the {name Functor.map}`map` operation must preserve identity and function composition. In other words, given a purported {name}`Functor` {lean}`f`, for all {lean}`x`​` : `​{lean}`f α`:
5160
* {lean}`id <$> x = x`, and
5261
* for all function {lean}`g` and {lean}`h`, {lean}`(h ∘ g) <$> x = h <$> g <$> x`.
5362

63+
:::
64+
65+
関手の場合、 {name Functor.map}`map` 演算は恒等関数と関数の合成を保持しなければなりません。言い換えると、 {name}`Functor` {lean}`f` が与えられた時、すべての {lean}`x`​` : `​{lean}`f α` に対して以下が成り立つことが必要です:
66+
* {lean}`id <$> x = x`
67+
* 全ての関数 {lean}`g` と {lean}`h` に対して、 {lean}`(h ∘ g) <$> x = h <$> g <$> x`
68+
69+
:::comment
5470
Instances that violate these assumptions can be very surprising!
5571
Additionally, because {lean}`Functor` includes {name Functor.mapConst}`mapConst` to enable instances to provide a more efficient implementation, a lawful functor's {name Functor.mapConst}`mapConst` should be equivalent to its default implementation.
5672

73+
:::
74+
75+
これらの仮定に反したインスタンスは非常に驚くようなものになりえます!さらに、 {lean}`Functor` には {name Functor.mapConst}`mapConst` が含まれており、インスタンスがより効率的な実装を提供できるようになっているため、合法的な関手の {name Functor.mapConst}`mapConst` はデフォルトの実装と同等であるべきです。
76+
77+
:::comment
5778
The Lean standard library does not require profs of these properties in every instance of {name}`Functor`.
5879
Nonetheless, if an instance violates them, then it should be considered a bug.
5980
When proofs of these properties are necessary, an instance implicit parameter of type {lean}`LawfulFunctor f` can be used.
6081
The {name}`LawfulFunctor` class includes the necessary proofs.
6182

83+
:::
84+
85+
Lean 標準ライブラリは {name}`Functor` のすべてのインスタンスにこれらの性質の証明を要求しているわけではありません。それにもかかわらず、インスタンスがそれらに違反する場合、それはバグとみなされるべきです。これらの性質の証明が必要な場合、 {lean}`LawfulFunctor f` 型のインスタンス暗黙パラメータを使用することができます。 {lean}`LawfulFunctor` クラスには必要な証明が含まれています。
86+
6287
{docstring LawfulFunctor}
6388

6489
```lean (show := false)
6590
end F
6691
```
67-
:::
92+
::::
6893

94+
:::comment
6995
In addition to proving that the potentially-optimized {name}`SeqLeft.seqLeft` and {name}`SeqRight.seqRight` operations are equivalent to their default implementations, Applicative functors {lean}`f` must satisfy four laws.
7096

97+
:::
98+
99+
最適化される可能性のある {name}`SeqLeft.seqLeft` と {name}`SeqRight.seqRight` の操作がデフォルト実装と同等であることを証明することに加え、アプリカティブ関手 {lean}`f`4つの規則を満たさなければなりません。
100+
71101
{docstring LawfulApplicative}
72102

103+
:::comment
73104
The {deftech}[monad laws] specify that {name}`pure` followed by {name}`bind` should be equivalent to function application (that is, {name}`pure` has no effects), that {name}`bind` followed by {name}`pure` around a function application is equivalent to {name Functor.map}`map`, and that {name}`bind` is associative.
74105

106+
:::
107+
108+
{deftech}[モナド則] (monad laws)では、 {name}`pure` の後に {name}`bind` が続いたものは関数適用と同等であること(つまり {name}`pure` は何の作用も持たない)、関数適用に対して {name}`bind` の後に {name}`pure` が続いたものは {name Functor.map}`map` と同等であること、 {name}`bind` が結合的であることを指定します。
109+
75110
{docstring LawfulMonad}
76111

77112
{docstring LawfulMonad.mk'}

0 commit comments

Comments
 (0)