47 lines
1.7 KiB
Text
47 lines
1.7 KiB
Text
universes v
|
|
/-
|
|
matcher for the following patterns
|
|
```
|
|
| "hello" => _
|
|
| "world" => _
|
|
| a => _
|
|
``` -/
|
|
def matchString (C : String → Sort v) (s : String)
|
|
(h₁ : Unit → C "hello")
|
|
(h₂ : Unit → C "world")
|
|
(h₃ : ∀ s, C s)
|
|
: C s :=
|
|
if h : s = "hello" then
|
|
@Eq.rec _ _ (fun x _ => C x) (h₁ ()) _ h.symm
|
|
else if h : s = "world" then
|
|
@Eq.rec _ _ (fun x _ => C x) (h₂ ()) _ h.symm
|
|
else
|
|
h₃ s
|
|
|
|
theorem matchString.Eq1 (C : String → Sort v)
|
|
(h₁ : Unit → C "hello")
|
|
(h₂ : Unit → C "world")
|
|
(h₃ : ∀ s, C s)
|
|
: matchString C "hello" h₁ h₂ h₃ = h₁ () :=
|
|
difPos rfl
|
|
|
|
axiom neg1 : "world" ≠ "hello"
|
|
|
|
theorem matchString.Eq2 (C : String → Sort v)
|
|
(h₁ : Unit → C "hello")
|
|
(h₂ : Unit → C "world")
|
|
(h₃ : ∀ s, C s)
|
|
: matchString C "world" h₁ h₂ h₃ = h₂ () :=
|
|
have aux₁ : matchString C "world" h₁ h₂ h₃ = if h : "world" = "world" then @Eq.rec _ _ (fun x _ => C x) (h₂ ()) _ h.symm else h₃ "world" from difNeg neg1;
|
|
have aux₂ : (if h : "world" = "world" then @Eq.rec _ _ (fun x _ => C x) (h₂ ()) _ h.symm else h₃ "world" : C "world") = h₂ () from difPos rfl;
|
|
Eq.trans aux₁ aux₂
|
|
|
|
theorem matchString.Eq3 (C : String → Sort v)
|
|
(h₁ : Unit → C "hello")
|
|
(h₂ : Unit → C "world")
|
|
(h₃ : ∀ s, C s)
|
|
(s : String) (n₁ : s ≠ "hello") (n₂ : s ≠ "world")
|
|
: matchString C s h₁ h₂ h₃ = h₃ s :=
|
|
have aux₁ : matchString C s h₁ h₂ h₃ = if h : s = "world" then @Eq.rec _ _ (fun x _ => C x) (h₂ ()) _ h.symm else h₃ s from difNeg n₁;
|
|
have aux₂ : (if h : s = "world" then @Eq.rec _ _ (fun x _ => C x) (h₂ ()) _ h.symm else h₃ s : C s) = h₃ s from difNeg n₂;
|
|
Eq.trans aux₁ aux₂
|