lean4-htt/tests/lean/matchMultAlt.lean
Leonardo de Moura 6d926c7989 feat: macro expand match alternatives
see #371

This commit does not implement all features discussed in this issue.
It has implemented it as a macro expansion. Thus, the following is
accepted
```lean
inductive StrOrNum where
  | S (s : String)
  | I (i : Int)

def StrOrNum.asString (x : StrOrNum) :=
  match x with
  | I a | S a => toString a
```
It may confuse the Lean LSP server. The `a` on `toString` shows the
information for the first alternative after expansion (i.e., `a` is an `Int`).
After expansion, we have
```
def StrOrNum.asString (x : StrOrNum) :=
  match x with
  | I a => toString a
  | S a => toString a
```
2022-03-20 14:20:13 -07:00

35 lines
622 B
Text

def f (x : Nat) : IO Unit := do
match x with
| 0 | 1 => IO.println "0 or 1"
| _ => IO.println "greater than 1"
#eval f 0
#eval f 1
#eval f 2
def g (x : Nat) : IO Unit :=
match x with
| 0 | 1 => IO.println "0 or 1"
| _ => IO.println "greater than 1"
#eval g 0
#eval g 1
#eval g 2
def h (x : Nat) : Nat :=
match x with
| 0 | 1 => 1
| x + 2 => x + 1
example : h x > 0 := by
match x with
| 0 | 1 => decide
| x + 2 => simp [h, Nat.add_succ]; simp_arith
inductive StrOrNum where
| S (s : String)
| I (i : Int)
def StrOrNum.asString (x : StrOrNum) :=
match x with
| I a | S a => toString a