Skip to content

Commit 3c46fd2

Browse files
committed
#check_failure が warning を出さなくなったことへの対応
1 parent a276a60 commit 3c46fd2

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

LeanByExample/Type/List.lean

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ example [Foldr α β] {a₁ a₂ a₃ : α} (init : β) :
139139
[a₁, a₂, a₃].foldr (· ⋄ ·) init = a₁ ⋄ a₂ ⋄ a₃ ⋄ init := by
140140
rfl
141141

142-
/- `List.foldl` と `List.foldr` の違いは、演算が左結合的と仮定するか右結合的と仮定するか以外にも、`List.foldl` は末尾再帰(tail recursion)であるが `List.foldr` はそうでないことが挙げられます。 -/
142+
/- `List.foldl` と `List.foldr` の違いは、演算が左結合的と仮定するか右結合的と仮定するか以外にも、`List.foldl` **末尾再帰(tail recursion)** であるが `List.foldr` はそうでないことが挙げられます。 -/
143143

144144
/-- 自然数のリストの総和を計算する関数 -/
145145
def List.sum' : List Nat → Nat
@@ -176,19 +176,14 @@ example : List.foldl (· + ·) 0 = List.sumTR := by
176176
Lean では、`List` は標準で `Monad` 型クラスのインスタンスになっていません。
177177
-/
178178

179-
/--
180-
error: failed to synthesize
181-
Monad List
182-
Additional diagnostic information may be available using the `set_option diagnostics true` command.
183-
-/
184-
#guard_msgs in
185-
#synth Monad List
179+
#check_failure (inferInstance : Monad List)
186180

187181
/- しかし、`Monad` 型クラスのインスタンスにすることは可能です。 -/
188182

189183
instance : Monad List where
190-
pure := List.singleton
191-
bind := List.flatMap
184+
pure x := [x]
185+
bind l f := l.flatMap f
186+
map f l := l.map f
192187

193188
/- `List` のモナドインスタンスを利用すると、「リスト `xs : List α` の中から要素 `x : α` を選んで `y : β` を構成することをすべての要素 `x ∈ xs` に対して繰り返し、結果の `y` を集めてリスト `ys : List β` を構成する」ということができます。 -/
194189

@@ -225,13 +220,18 @@ def tablen (n : Nat) (p : Arity Bool n) : List (List Bool) :=
225220
let rest ← tablen n (p b)
226221
return b :: rest
227222

228-
/-- info: [[true, true, true],
229-
[true, false, false],
230-
[false, true, false],
231-
[false, false, false]] -/
232-
#guard_msgs (whitespace := lax) in
233-
#eval tablen 2 (fun a b => a && b)
234-
235-
-- 結果が false になるものだけ表示
236-
#guard [[false, false, false, false]] =
237-
(tablen 3 (fun a b c => a || b || c) |>.filter (fun xs => ! xs.getLast!))
223+
#guard
224+
let expected := [
225+
[true, true, true],
226+
[true, false, false],
227+
[false, true, false],
228+
[false, false, false]
229+
]
230+
let actual := tablen 2 (fun a b => a && b)
231+
expected = actual
232+
233+
#guard
234+
let result := tablen 3 (fun a b c => a || b || c)
235+
236+
-- 結果が false になるものだけ集める
237+
result.filter (fun xs => ! xs.getLast!) = [[false, false, false, false]]

LeanByExample/TypeClass/CoeFun.lean

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,7 @@ local instance : Coe AdditiveFunction (Nat → Nat) where
4040

4141
-- `Nat → Nat` への型強制が呼び出されず、エラーになってしまう
4242
-- これは、期待されている型が `Nat → Nat` ではなく、単に `Nat → ?_` であるため。
43-
/--
44-
warning: function expected at
45-
identity
46-
term has type
47-
AdditiveFunction
48-
-/
49-
#guard_msgs in
50-
#check_failure (identity 1)
43+
#check_failure (identity 1)
5144

5245
-- 期待される型を明記すればエラーにならない
5346
#check ((identity : Nat → Nat) 1)

0 commit comments

Comments
 (0)