Skip to content

Commit a63ba48

Browse files
committed
fixes agda#2059 on the model of agda#2336
1 parent ad0fb0e commit a63ba48

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

src/Data/List/Relation/Unary/First/Properties.agda

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ open import Data.List.Base as List using (List; []; _∷_)
1313
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
1414
open import Data.List.Relation.Unary.Any as Any using (here; there)
1515
open import Data.List.Relation.Unary.First
16-
import Data.Sum as Sum
17-
open import Function.Base using (_∘′_; _$_; _∘_; id)
16+
import Data.Sum.Base as Sum
17+
open import Function.Base using (_∘′_; _∘_; id)
1818
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_; refl; _≗_)
19+
import Relation.Nullary.Decidable.Core as Dec
20+
open import Relation.Nullary.Negation.Core using (contradiction)
1921
open import Relation.Unary using (Pred; _⊆_; ∁; Irrelevant; Decidable)
20-
open import Relation.Nullary.Negation using (contradiction)
2122

2223
------------------------------------------------------------------------
2324
-- map
@@ -80,14 +81,14 @@ module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
8081
module _ {a p} {A : Set a} {P : Pred A p} where
8182

8283
first? : Decidable P Decidable (First P (∁ P))
83-
first? P? xs = Sum.toDec
84-
$ Sum.map₂ (All⇒¬First contradiction)
85-
$ first (Sum.fromDec ∘ P?) xs
84+
first? P? = Dec.fromSum
85+
Sum.map₂ (All⇒¬First contradiction)
86+
first (Dec.toSum ∘ P?)
8687

8788
cofirst? : Decidable P Decidable (First (∁ P) P)
88-
cofirst? P? xs = Sum.toDec
89-
$ Sum.map₂ (All⇒¬First id)
90-
$ first (Sum.swap ∘ Sum.fromDec ∘ P?) xs
89+
cofirst? P? = Dec.fromSum
90+
Sum.map₂ (All⇒¬First id)
91+
first (Sum.swap ∘ Dec.toSum ∘ P?)
9192

9293
------------------------------------------------------------------------
9394
-- Conversion to Any

src/Data/Sum.agda

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ open import Data.Unit.Polymorphic.Base using (⊤; tt)
1515
open import Data.Maybe.Base using (Maybe; just; nothing)
1616
open import Function.Base
1717
open import Level
18-
open import Relation.Nullary.Reflects using (invert)
19-
open import Relation.Nullary using (Dec; yes; no; _because_; ¬_)
18+
import Relation.Nullary.Decidable.Core as Dec
2019

2120
private
2221
variable
@@ -57,12 +56,13 @@ module _ {a b} {A : Set a} {B : Set b} where
5756
from-inj₂ (inj₁ _) = _
5857
from-inj₂ (inj₂ x) = x
5958

60-
-- Conversion back and forth with Dec
59+
------------------------------------------------------------------------
60+
-- DEPRECATED NAMES
61+
------------------------------------------------------------------------
62+
-- Please use the new names as continuing support for the old names is
63+
-- not guaranteed.
64+
65+
-- Version 2.1
6166

62-
fromDec : Dec A A ⊎ ¬ A
63-
fromDec ( true because [p]) = inj₁ (invert [p])
64-
fromDec (false because [¬p]) = inj₂ (invert [¬p])
67+
open Dec public using (fromDec; toDec)
6568

66-
toDec : A ⊎ ¬ A Dec A
67-
toDec (inj₁ p) = yes p
68-
toDec (inj₂ ¬p) = no ¬p

src/Relation/Nullary/Decidable/Core.agda

+26-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ open import Level using (Level; Lift)
1616
open import Data.Bool.Base using (Bool; T; false; true; not; _∧_; _∨_)
1717
open import Data.Unit.Polymorphic.Base using (⊤)
1818
open import Data.Product.Base using (_×_)
19-
open import Data.Sum.Base using (_⊎_)
19+
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
2020
open import Function.Base using (_∘_; const; _$_; flip)
2121
open import Relation.Nullary.Recomputable as Recomputable hiding (recompute-constant)
2222
open import Relation.Nullary.Reflects as Reflects hiding (recompute; recompute-constant)
@@ -103,6 +103,17 @@ _→-dec_ : Dec A → Dec B → Dec (A → B)
103103
does (a? →-dec b?) = not (does a?) ∨ does b?
104104
proof (a? →-dec b?) = proof a? →-reflects proof b?
105105

106+
------------------------------------------------------------------------
107+
-- Relationship with Sum
108+
109+
toSum : Dec A A ⊎ ¬ A
110+
toSum ( true because [p]) = inj₁ (invert [p])
111+
toSum (false because [¬p]) = inj₂ (invert [¬p])
112+
113+
fromSum : A ⊎ ¬ A Dec A
114+
fromSum (inj₁ p) = yes p
115+
fromSum (inj₂ ¬p) = no ¬p
116+
106117
------------------------------------------------------------------------
107118
-- Relationship with booleans
108119

@@ -201,3 +212,17 @@ excluded-middle = ¬¬-excluded-middle
201212
"Warning: excluded-middle was deprecated in v2.0.
202213
Please use ¬¬-excluded-middle instead."
203214
#-}
215+
216+
-- Version 2.1
217+
218+
fromDec = toSum
219+
{-# WARNING_ON_USAGE fromDec
220+
"Warning: fromDec was deprecated in v2.1.
221+
Please use Relation.Nullary.Decidable.Core.toSum instead."
222+
#-}
223+
224+
toDec = fromSum
225+
{-# WARNING_ON_USAGE toDec
226+
"Warning: toDec was deprecated in v2.1.
227+
Please use Relation.Nullary.Decidable.Core.fromSum instead."
228+
#-}

0 commit comments

Comments
 (0)