2014-12-22 20:33:29 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Module: data.option
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
-/
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
import logic.eq
|
2014-10-02 00:51:17 +00:00
|
|
|
open eq.ops decidable
|
2014-08-01 01:40:09 +00:00
|
|
|
|
2014-09-04 23:36:06 +00:00
|
|
|
namespace option
|
2015-05-04 04:40:33 +00:00
|
|
|
definition is_none {A : Type} : option A → Prop
|
|
|
|
| none := true
|
|
|
|
| (some v) := false
|
2014-09-05 05:31:52 +00:00
|
|
|
|
|
|
|
theorem is_none_none {A : Type} : is_none (@none A) :=
|
|
|
|
trivial
|
|
|
|
|
|
|
|
theorem not_is_none_some {A : Type} (a : A) : ¬ is_none (some a) :=
|
2014-12-01 04:34:12 +00:00
|
|
|
not_false
|
2014-09-05 05:31:52 +00:00
|
|
|
|
|
|
|
theorem none_ne_some {A : Type} (a : A) : none ≠ some a :=
|
2015-04-30 20:56:12 +00:00
|
|
|
by contradiction
|
2014-09-05 05:31:52 +00:00
|
|
|
|
2014-11-17 01:56:51 +00:00
|
|
|
theorem some.inj {A : Type} {a₁ a₂ : A} (H : some a₁ = some a₂) : a₁ = a₂ :=
|
2015-05-02 01:18:29 +00:00
|
|
|
by injection H; assumption
|
2014-09-05 05:31:52 +00:00
|
|
|
|
2014-10-02 16:00:34 +00:00
|
|
|
protected definition is_inhabited [instance] (A : Type) : inhabited (option A) :=
|
2014-09-05 05:31:52 +00:00
|
|
|
inhabited.mk none
|
|
|
|
|
2015-05-04 04:40:33 +00:00
|
|
|
protected definition has_decidable_eq [instance] {A : Type} [H : decidable_eq A] : ∀ o₁ o₂ : option A, decidable (o₁ = o₂)
|
|
|
|
| none none := by left; reflexivity
|
|
|
|
| none (some v₂) := by right; contradiction
|
|
|
|
| (some v₁) none := by right; contradiction
|
|
|
|
| (some v₁) (some v₂) :=
|
|
|
|
match H v₁ v₂ with
|
|
|
|
| inl e := by left; congruence; assumption
|
|
|
|
| inr n := by right; intro h; injection h; refine absurd _ n; assumption
|
|
|
|
end
|
2014-08-20 02:32:44 +00:00
|
|
|
end option
|