You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 5, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: Manual/Monads/Laws.lean
+37-2Lines changed: 37 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,10 @@ set_option pp.rawOnError true
19
19
20
20
set_option linter.unusedVariables false
21
21
22
+
/-
22
23
#doc (Manual) "Laws" =>
24
+
-/
25
+
#doc (Manual) "規則(Laws)" =>
23
26
%%%
24
27
tag := "monad-laws"
25
28
%%%
@@ -38,40 +41,72 @@ axiom γ : Type u'
38
41
axiomx : f α
39
42
```
40
43
41
-
:::keepEnv
44
+
::::keepEnv
42
45
```lean (show := false)
43
46
section F
44
47
variable {f : Type u → Type v} [Functor f] {α β : Type u} {g : α → β} {h : β → γ} {x : f α}
45
48
```
46
49
50
+
:::comment
47
51
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.
48
52
These operators must additionally satisfy certain axioms, which are often called the {deftech}_laws_ of the type class.
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 α`:
51
60
* {lean}`id <$> x = x`, and
52
61
* for all function {lean}`g` and {lean}`h`, {lean}`(h ∘ g) <$> x = h <$> g <$> x`.
* 全ての関数 {lean}`g` と {lean}`h` に対して、 {lean}`(h ∘ g) <$> x = h <$> g <$> x`
68
+
69
+
:::comment
54
70
Instances that violate these assumptions can be very surprising!
55
71
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.
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.
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.
0 commit comments