lean4-htt/tests/lean/match2.lean
Leonardo de Moura 4ee131981d feat: in an inductive family the longest fixed prefix of indices is now promoted to parameters
This modification is relevant for fixing regressions on recent changes
to the auto implicit behavior for inductive families.

The following declarations are now accepted:
```lean
inductive HasType : Fin n → Vector Ty n → Ty → Type where
  | stop : HasType 0 (ty :: ctx) ty
  | pop  : HasType k ctx ty → HasType k.succ (u :: ctx) ty

inductive Sublist : List α → List α → Prop
  | slnil : Sublist [] []
  | cons l₁ l₂ a : Sublist l₁ l₂ → Sublist l₁ (a :: l₂)
  | cons2 l₁ l₂ a : Sublist l₁ l₂ → Sublist (a :: l₁) (a :: l₂)

inductive Lst : Type u → Type u
  | nil  : Lst α
  | cons : α → Lst α → Lst α
```

TODO: universe inference for `inductive` should be improved. The
current approach is not good enough when we have auto implicits.

TODO: allow implicit fixed indices that do not depend on indices that
cannot be moved to become parameters.
2022-03-08 17:56:34 -08:00

90 lines
1.9 KiB
Text

#print "---- Op"
inductive Op : Nat → Nat → Type
| mk : ∀ n, Op n n
structure Node : Type where
id₁ : Nat
id₂ : Nat
o : Op id₁ id₂
def h1 (x : List Node) : Bool :=
match x with
| _ :: Node.mk 0 _ Op.mk :: _ => true
| _ => false
def mkNode (n : Nat) : Node := { id₁ := n, id₂ := n, o := Op.mk }
#eval h1 [mkNode 1, mkNode 0, mkNode 3]
#eval h1 [mkNode 1, mkNode 1, mkNode 3]
#eval h1 [mkNode 0]
#eval h1 []
#print "---- Foo 1"
inductive Foo : Bool → Type
| bar : Foo false
| baz : Foo false
def h2 {b : Bool} (x : Foo b) : Bool :=
match b, x with
| _, Foo.bar => true
| _, Foo.baz => false
#eval h2 Foo.bar
#eval h2 Foo.baz
def h2' {b : Bool} (x : Foo b) : Bool :=
match x with
| Foo.bar => true
| Foo.baz => false
#print "---- Foo 2"
def h3 {b : Bool} (x : Foo b) : Bool :=
match b, x with
| _, Foo.bar => true
| _, _ => false
#eval h3 Foo.bar
#eval h3 Foo.baz
#print "---- Op 2"
def h4 (x : List Node) : Bool :=
match x with
| _ :: ⟨1, 1, Op.mk⟩ :: _ => true
| _ => false
#eval h4 [mkNode 1, mkNode 0, mkNode 3]
#eval h4 [mkNode 1, mkNode 1, mkNode 3]
#eval h4 [mkNode 0]
#eval h4 []
#print "---- Foo 3"
set_option pp.all true
def h5 {b : Bool} (x : Foo b) : Bool :=
match b, x with
| _, Foo.bar => true
| c, y => false
def h5' {b : Bool} (x : Foo b) : Bool :=
match x with
| Foo.bar => true
| y => false
def h6 {b : Bool} (x : Foo b) : Bool :=
match b, x with
| _, Foo.bar => true
| b, x => false
def h6' {b : Bool} (x : Foo b) : Bool :=
match (generalizing := true) (motive := (b : Bool) → Foo b → Bool) b, x with
| _, Foo.bar => true
| b, x => false
def h6'' {b : Bool} (x : Foo b) : Bool :=
match (generalizing := false) (motive := (b : Bool) → Foo b → Bool) b, x with
| _, Foo.bar => true
| b, x => false