Skip to content

Commit dc7ef5f

Browse files
authored
[ add ] Reflects for unit and empty types (#2727)
* add: `Reflects` for unit and empty types * refactor: `Decidable.Core` * tweaks; `CHANGELOG`
1 parent ac6571b commit dc7ef5f

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,9 @@ Additions to existing modules
320320
```agda
321321
contra-diagonal : (A → ¬ A) → ¬ A
322322
```
323+
324+
* In `Relation.Nullary.Reflects`:
325+
```agda
326+
⊤-reflects : Reflects (⊤ {a}) true
327+
⊥-reflects : Reflects (⊥ {a}) false
328+
```

src/Relation/Nullary/Decidable/Core.agda

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ open import Agda.Builtin.Equality using (_≡_)
1717
open import Agda.Builtin.Maybe using (Maybe; just; nothing)
1818
open import Level using (Level)
1919
open import Data.Bool.Base using (Bool; T; false; true; not; _∧_; _∨_)
20-
open import Data.Unit.Polymorphic.Base using (⊤; tt)
20+
open import Data.Unit.Polymorphic.Base using (⊤)
2121
open import Data.Empty.Polymorphic using (⊥)
2222
open import Data.Product.Base using (_×_)
2323
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
@@ -99,15 +99,15 @@ proof (¬? a?) = ¬-reflects (proof a?)
9999

100100
⊤-dec : Dec {a} ⊤
101101
does ⊤-dec = true
102-
proof ⊤-dec = ofʸ tt
102+
proof ⊤-dec = ⊤-reflects
103103

104104
_×-dec_ : Dec A Dec B Dec (A × B)
105105
does (a? ×-dec b?) = does a? ∧ does b?
106106
proof (a? ×-dec b?) = proof a? ×-reflects proof b?
107107

108108
⊥-dec : Dec {a} ⊥
109109
does ⊥-dec = false
110-
proof ⊥-dec = ofⁿ λ ()
110+
proof ⊥-dec = ⊥-reflects
111111

112112
_⊎-dec_ : Dec A Dec B Dec (A ⊎ B)
113113
does (a? ⊎-dec b?) = does a? ∨ does b?

src/Relation/Nullary/Reflects.agda

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ open import Agda.Builtin.Equality
1313
open import Data.Bool.Base
1414
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
1515
open import Data.Product.Base using (_×_; _,_; proj₁; proj₂)
16+
open import Data.Unit.Polymorphic.Base using (⊤)
17+
open import Data.Empty.Polymorphic using (⊥)
1618
open import Level using (Level)
1719
open import Function.Base using (_$_; _∘_; const; id)
1820
open import Relation.Nullary.Negation.Core
@@ -66,21 +68,25 @@ recompute-constant : ∀ {b} (r : Reflects A b) (p q : A) →
6668
recompute-constant = Recomputable.recompute-constant ∘ recompute
6769

6870
------------------------------------------------------------------------
69-
-- Interaction with negation, product, sums etc.
71+
-- Interaction with true, false, negation, product, sums etc.
7072

7173
infixr 1 _⊎-reflects_
7274
infixr 2 _×-reflects_ _→-reflects_
7375

76+
⊥-reflects : Reflects (⊥ {a}) false
77+
⊥-reflects = of λ()
78+
79+
⊤-reflects : Reflects (⊤ {a}) true
80+
⊤-reflects = of _
81+
7482
T-reflects : b Reflects (T b) b
7583
T-reflects true = of _
7684
T-reflects false = of id
7785

78-
-- If we can decide A, then we can decide its negation.
7986
¬-reflects : {b} Reflects A b Reflects (¬ A) (not b)
8087
¬-reflects (ofʸ a) = of (_$ a)
8188
¬-reflects (ofⁿ ¬a) = of ¬a
8289

83-
-- If we can decide A and Q then we can decide their product
8490
_×-reflects_ : {a b} Reflects A a Reflects B b
8591
Reflects (A × B) (a ∧ b)
8692
ofʸ a ×-reflects ofʸ b = of (a , b)

0 commit comments

Comments
 (0)