lean-ja / lean-ja/lean-by-example
match 用に専用のラッパーを作る例 (match 式の融通の利かなさを何とかする例)
Open
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
lean-ja における Yuki さんの投稿から。
namespace String
@[ext]
structure ValidPosPlusOne (s : String) where
offset : Pos.Raw
isValidOrPlusOne : offset.IsValid s ∨ offset = s.rawEndPos.offsetBy ⟨1⟩
inductive ValidPosPlusOne' (s : String) : Type where
| validPos (p : ValidPos s) : ValidPosPlusOne' s
| sentinel : ValidPosPlusOne' s
#check ValidPosPlusOne.mk
#check ValidPosPlusOne'.sentinel
def wrap (s : String) (p : ValidPosPlusOne s) : ValidPosPlusOne' s := by
by_cases h : p.offset = s.rawEndPos.offsetBy ⟨1⟩
exact ValidPosPlusOne'.sentinel
have h' : p.offset.IsValid s := by
cases p.isValidOrPlusOne with
| inl h => exact h
| inr h => contradiction
exact ValidPosPlusOne'.validPos ⟨ p.offset, h' ⟩
namespace ValidPosPlusOne
variable {s : String}
example {s : String} (p : ValidPosPlusOne s) (p' := wrap s p) : Nat :=
match p' with
| .validPos pos => 1 -- It works!
| .sentinel => 2
end ValidPosPlusOne
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
No file or test is named. Start by locating where comparable Lean examples are kept, then use the wrapper example in the issue as the reference. Done means the repository includes a clear example showing how the dedicated wrapper makes the match expression work.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100