lean-ja / lean-ja/lean-by-example

Subtype に対してパターンマッチが通るようにしたい

Open
#1,456 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

コード例 データ型
Dominant language
Lean
Stars
188
Forks
15
Avg merge
9h 8m
Merged PRs (30d)
6

Description

PosNat に対して、n + 1 でパターンマッチができないのか?
何が難しい?難しさもわかっていない。Subtype について、わりと大事な話な気がする。

Zulip: >
pattern match for positive Nat

abbrev PosNat := { x : Nat // x > 0}

@[match_pattern]
def PosNat.add (x y : PosNat) : PosNat :=
  ⟨x.val + y.val, by omega⟩

instance : Add PosNat := ⟨PosNat.add⟩

def PosNat.one : PosNat := ⟨1, by decide⟩

instance : OfNat PosNat 1 := ⟨PosNat.one⟩

def seq (x : PosNat) : ℝ :=
  match x with
  | 1 => 1
  /- invalid patterns, `n` is an explicit pattern variable, but it only occurs in positions that are inaccessible to pattern matching
  ⟨.(n.1).succ, ⋯⟩ -/
  | n + 1 => seq n

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PosNat example and the linked Zulip discussion about pattern matching for positive Nat. Investigate how subtype patterns, inaccessible pattern variables, and the n + 1 notation are handled in Lean's pattern-matching implementation. Done would require a decided approach and a documented or tested way for this match to work.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.