Skip to content

Commit

Permalink
Feat: Add computable rec for Option via rec_eq_recC pattern (#3255)
Browse files Browse the repository at this point in the history
Adds a computable recursor for `Option`



Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
  • Loading branch information
arienmalec and eric-wieser committed Apr 4, 2023
1 parent 2dd4be1 commit 7647a76
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Mathlib/Data/Option/Basic.lean
Expand Up @@ -362,6 +362,26 @@ theorem casesOn'_none_coe (f : Option α → β) (o : Option α) :
casesOn' o (f none) (f ∘ (fun a ↦ ↑a)) = f o := by cases o <;> rfl
#align option.cases_on'_none_coe Option.casesOn'_none_coe

-- porting note: workaround for leanprover/lean4#2049
section recursor_workarounds

/-- A computable version of `Option.rec`. Workaround until Lean has native support for this. -/
def recC.{u_1, u} {α : Type u} {motive : Option α → Sort u_1} (none : motive none)
(some : (val : α) → motive (some val)) :
(t : Option α) → motive t
| Option.none => none
| Option.some a => some a

@[csimp]
lemma rec_eq_recC : @Option.rec = @Option.recC := by
ext α motive none some o
induction o with
| none => rfl
| some a =>
rw [Option.recC]

end recursor_workarounds

theorem orElse_eq_some (o o' : Option α) (x : α) :
(o <|> o') = some x ↔ o = some x ∨ o = none ∧ o' = some x := by
cases o
Expand Down

0 comments on commit 7647a76

Please sign in to comment.