lean-ja / lean-ja/lean-by-example
outParam が予想外の挙動をする例
Open
Nobody has claimed this yet.
データ型
メモ
宣言的コマンド
要調査
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
universe u v w
namespace Ex
/-- `outParam` なしで定義したダメな例 -/
class BadHMul (α : Type u) (β : Type v) (γ : Type w) where
hMul : α → β → γ
instance : BadHMul Nat Nat Nat where
hMul := Nat.mul
-- 返り値の型がわからないのでエラーになる
#check_failure BadHMul.hMul 1 2
-- 返り値の型を指定すればエラーにならない
#check (BadHMul.hMul 1 2 : Nat)
class HMul (α : Type u) (β : Type v) (γ : outParam (Type w)) where
hMul : α → β → γ
instance : HMul Nat Nat (List Nat) where
hMul x y := []
#check (HMul.hMul 1 4 : List Nat)
instance : HMul Nat Nat Nat where
hMul := Nat.mul
-- 返り値の型を自動で推論してくれて,エラーにならない
#eval HMul.hMul 4 3 -- 12
-- なぜか List Nat に変換する方だと解釈してくれない
-- outParam を付けたことで, Nat → Nat → Nat が優先される???
-- 怪奇現象
#check_failure (HMul.hMul 1 4 : List Nat) -- 4
instance : HMul Nat String Unit where
hMul x y := ()
instance : HMul Nat String (List Nat) where
hMul x y := []
-- これはいける
-- そして Unit が優先される(インスタンスの宣言順序は無関係)
#eval HMul.hMul 3 "hello"
instance : HMul Nat Nat Unit where
hMul x y := ()
-- これは掛け算が勝つ
#guard HMul.hMul 2 3 = 6
end Ex
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Lean example and reproducing each reported success or failure, especially the outParam cases. Trace how instance and result-type inference selects HMul instances, then document an explanation of the observed behavior and clarify what correction or example change is needed.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100