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
|
2014-09-05 05:31:52 +00:00
|
|
|
definition is_none {A : Type} (o : option A) : Prop :=
|
2015-02-11 20:49:27 +00:00
|
|
|
option.rec true (λ a, false) o
|
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-02-11 20:49:27 +00:00
|
|
|
assume H, option.no_confusion H
|
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-02-11 20:49:27 +00:00
|
|
|
option.no_confusion H (λe, e)
|
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-02-24 23:25:02 +00:00
|
|
|
protected definition has_decidable_eq [instance] {A : Type} [H : decidable_eq A] : decidable_eq (option A) :=
|
2014-09-09 23:07:07 +00:00
|
|
|
take o₁ o₂ : option A,
|
2015-02-11 20:49:27 +00:00
|
|
|
option.rec_on o₁
|
|
|
|
(option.rec_on o₂ (inl rfl) (take a₂, (inr (none_ne_some a₂))))
|
|
|
|
(take a₁ : A, option.rec_on o₂
|
2014-09-08 05:22:04 +00:00
|
|
|
(inr (ne.symm (none_ne_some a₁)))
|
|
|
|
(take a₂ : A, decidable.rec_on (H a₁ a₂)
|
|
|
|
(assume Heq : a₁ = a₂, inl (Heq ▸ rfl))
|
2014-11-17 01:56:51 +00:00
|
|
|
(assume Hne : a₁ ≠ a₂, inr (assume Hn : some a₁ = some a₂, absurd (some.inj Hn) Hne))))
|
2014-08-20 02:32:44 +00:00
|
|
|
end option
|