Skip to content

Commit 086a72e

Browse files
JacquesCarettegallaisjamesmckinna
authored
Implement move-via-deprecate of decToMaybe as per #2330 (#2336)
* Make the main home of `decToMaybe` be `Relation.Nullary.Decidable.Core`, but deprecate the one in `Data.Maybe.Base` instead of removing it entirely. Fix the library accordingly. Note that this forces `Relation.Nullary.Decidable.Core` to use `Agda.Builtin.Maybe` to avoid a cyclic import. This can be fixed once the deprecation is done. * Update src/Relation/Nullary/Decidable/Core.agda Good idea. Co-authored-by: G. Allais <[email protected]> * simplified the deprecation * `CHANGELOG` * narrowed import too far * tweak a couple of the solvers for consistency, as per suggestions. * chnage to `public` re-export of `Relation.Nullary.Decidable.Core.decToMaybe` * Revert "chnage to `public` re-export of `Relation.Nullary.Decidable.Core.decToMaybe`" This reverts commit 256a505. * `fix-whitespace` * simplify `import`s * make consistent with `Idempotent` case * tidy up * instead of an alias, open public so that Agda knows these really are the same. This is a better deprecation strategy. * rename(provisional)+deprecate * knock-on * knock-on: refactor via `dec⇒maybe` * deprecation via delegation * fix `CHANGELOG` --------- Co-authored-by: G. Allais <[email protected]> Co-authored-by: James McKinna <[email protected]> Co-authored-by: jamesmckinna <[email protected]>
1 parent 1e42bf4 commit 086a72e

File tree

9 files changed

+66
-34
lines changed

9 files changed

+66
-34
lines changed

CHANGELOG.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ Deprecated names
7676
_-_ ↦ _//_
7777
```
7878

79+
* In `Data.Maybe.Base`:
80+
```agda
81+
decToMaybe ↦ Relation.Nullary.Decidable.Core.dec⇒maybe
82+
```
83+
7984
* In `Algebra.Structures.Biased`:
8085
```agda
8186
IsRing* ↦ Algebra.Structures.IsRing
@@ -821,8 +826,9 @@ Additions to existing modules
821826
WeaklyDecidable : Set _
822827
```
823828

824-
* Added new proof in `Relation.Nullary.Decidable.Core`:
829+
* Added new definition and proof in `Relation.Nullary.Decidable.Core`:
825830
```agda
831+
dec⇒maybe : Dec A → Maybe A
826832
recompute-constant : (a? : Dec A) (p q : A) → recompute a? p ≡ recompute a? q
827833
toSum : Dec A → A ⊎ ¬ A
828834
fromSum : A ⊎ ¬ A → Dec A
@@ -842,7 +848,7 @@ Additions to existing modules
842848
```agda
843849
recompute : Reflects A b → Recomputable A
844850
recompute-constant : (r : Reflects A b) (p q : A) → recompute r p ≡ recompute r q
845-
```
851+
```
846852

847853
* Added new definitions in `Relation.Unary`
848854
```

src/Algebra/Solver/CommutativeMonoid.agda

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Algebra.Solver.CommutativeMonoid {m₁ m₂} (M : CommutativeMonoid m₁
1414

1515
open import Data.Fin.Base using (Fin; zero; suc)
1616
open import Data.Maybe.Base as Maybe
17-
using (Maybe; decToMaybe; From-just; from-just)
17+
using (Maybe; From-just; from-just)
1818
open import Data.Nat as ℕ using (ℕ; zero; suc; _+_)
1919
open import Data.Nat.GeneralisedArithmetic using (fold)
2020
open import Data.Product.Base using (_×_; uncurry)
@@ -27,8 +27,9 @@ import Relation.Binary.Reflection as Reflection
2727
import Relation.Nullary.Decidable as Dec
2828
import Data.Vec.Relation.Binary.Pointwise.Inductive as Pointwise
2929

30+
open import Relation.Binary.Consequences using (dec⇒weaklyDec)
3031
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
31-
open import Relation.Nullary.Decidable using (Dec)
32+
open import Relation.Nullary.Decidable as Dec using (Dec)
3233

3334
open CommutativeMonoid M
3435
open ≈-Reasoning setoid
@@ -184,7 +185,7 @@ nf₁ ≟ nf₂ = Dec.map Pointwise-≡↔≡ (decidable ℕ._≟_ nf₁ nf₂)
184185

185186
prove′ : (e₁ e₂ : Expr n) Maybe ( ρ ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ)
186187
prove′ e₁ e₂ =
187-
Maybe.map lemma (decToMaybe (normalise e₁normalise e₂))
188+
Maybe.map lemma (dec⇒weaklyDec _≟_ (normalise e₁) (normalise e₂))
188189
where
189190
lemma : normalise e₁ ≡ normalise e₂ ρ ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ
190191
lemma eq ρ =

src/Algebra/Solver/IdempotentCommutativeMonoid.agda

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open import Algebra.Bundles using (IdempotentCommutativeMonoid)
1313
open import Data.Bool as Bool using (Bool; true; false; if_then_else_; _∨_)
1414
open import Data.Fin.Base using (Fin; zero; suc)
1515
open import Data.Maybe.Base as Maybe
16-
using (Maybe; decToMaybe; From-just; from-just)
16+
using (Maybe; From-just; from-just)
1717
open import Data.Nat.Base as ℕ using (ℕ; zero; suc; _+_)
1818
open import Data.Product.Base using (_×_; uncurry)
1919
open import Data.Vec.Base using (Vec; []; _∷_; lookup; replicate)
@@ -22,12 +22,13 @@ open import Function.Base using (_∘_)
2222

2323
import Relation.Binary.Reasoning.Setoid as ≈-Reasoning
2424
import Relation.Binary.Reflection as Reflection
25-
import Relation.Nullary.Decidable as Dec
2625
import Data.Vec.Relation.Binary.Pointwise.Inductive as Pointwise
2726

27+
open import Relation.Binary.Consequences using (dec⇒weaklyDec)
2828
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
2929
open import Relation.Binary.PropositionalEquality.Properties using (decSetoid)
30-
open import Relation.Nullary.Decidable using (Dec)
30+
open import Relation.Nullary.Decidable as Dec using (Dec)
31+
3132

3233
module Algebra.Solver.IdempotentCommutativeMonoid
3334
{m₁ m₂} (M : IdempotentCommutativeMonoid m₁ m₂) where
@@ -198,7 +199,7 @@ nf₁ ≟ nf₂ = Dec.map Pointwise-≡↔≡ (decidable Bool._≟_ nf₁ nf₂)
198199

199200
prove′ : (e₁ e₂ : Expr n) Maybe ( ρ ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ)
200201
prove′ e₁ e₂ =
201-
Maybe.map lemma (decToMaybe (normalise e₁normalise e₂))
202+
Maybe.map lemma (dec⇒weaklyDec _≟_ (normalise e₁) (normalise e₂))
202203
where
203204
lemma : normalise e₁ ≡ normalise e₂ ρ ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ
204205
lemma eq ρ =

src/Algebra/Solver/Monoid.agda

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import Data.Fin.Properties as Fin
1515
open import Data.List.Base hiding (lookup)
1616
import Data.List.Relation.Binary.Equality.DecPropositional as ListEq
1717
open import Data.Maybe.Base as Maybe
18-
using (Maybe; decToMaybe; From-just; from-just)
18+
using (Maybe; From-just; from-just)
1919
open import Data.Nat.Base using (ℕ)
2020
open import Data.Product.Base using (_×_; uncurry)
2121
open import Data.Vec.Base using (Vec; lookup)
2222
open import Function.Base using (_∘_; _$_)
23+
open import Relation.Binary.Consequences using (dec⇒weaklyDec)
2324
open import Relation.Binary.Definitions using (DecidableEquality)
2425

2526
open import Relation.Binary.PropositionalEquality.Core using (_≡_; cong)
2627
import Relation.Binary.Reflection
27-
open import Relation.Nullary
28-
import Relation.Nullary.Decidable as Dec
28+
import Relation.Nullary.Decidable.Core as Dec
2929

3030
open Monoid M
3131
open import Relation.Binary.Reasoning.Setoid setoid
@@ -123,7 +123,7 @@ nf₁ ≟ nf₂ = Dec.map′ ≋⇒≡ ≡⇒≋ (nf₁ ≋? nf₂)
123123

124124
prove′ : {n} (e₁ e₂ : Expr n) Maybe ( ρ ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ)
125125
prove′ e₁ e₂ =
126-
Maybe.map lemma $ decToMaybe (normalise e₁normalise e₂)
126+
Maybe.map lemma $ dec⇒weaklyDec _≟_ (normalise e₁) (normalise e₂)
127127
where
128128
lemma : normalise e₁ ≡ normalise e₂ ρ ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ
129129
lemma eq ρ =

src/Data/Graph/Acyclic.agda

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ open import Data.Fin as Fin
2020
using (Fin; Fin′; zero; suc; #_; toℕ; _≟_; opposite) renaming (_ℕ-ℕ_ to _-_)
2121
import Data.Fin.Properties as Fin
2222
open import Data.Product.Base as Prod using (∃; _×_; _,_)
23-
open import Data.Maybe.Base as Maybe using (Maybe; nothing; just; decToMaybe)
24-
open import Data.Empty
23+
open import Data.Maybe.Base as Maybe using (Maybe)
24+
open import Data.Empty using (⊥)
2525
open import Data.Unit.Base using (⊤; tt)
2626
open import Data.Vec.Base as Vec using (Vec; []; _∷_)
2727
open import Data.List.Base as List using (List; []; _∷_)
2828
open import Function.Base using (_$_; _∘′_; _∘_; id)
29-
open import Relation.Nullary
29+
open import Relation.Binary.Consequences using (dec⇒weaklyDec)
3030
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
3131

3232
------------------------------------------------------------------------
@@ -238,7 +238,7 @@ preds (c & g) (suc i) =
238238
(List.map (Prod.map suc id) $ preds g i)
239239
where
240240
p : {e} {E : Set e} {n} (i : Fin n) E × Fin n Maybe (Fin′ (suc i) × E)
241-
p i (e , j) = Maybe.map (λ{ refl zero , e }) (decToMaybe (i ≟ j))
241+
p i (e , j) = Maybe.map (λ{ refl zero , e }) (dec⇒weaklyDec _≟_ i j)
242242

243243
private
244244

src/Data/List/Relation/Binary/Sublist/Heterogeneous/Solver.agda

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Data.List.Relation.Binary.Sublist.Heterogeneous.Solver
2121

2222
open import Level using (_⊔_)
2323
open import Data.Fin as Fin
24-
open import Data.Maybe.Base as Maybe
24+
open import Data.Maybe.Base as Maybe using (Maybe; nothing; just; From-just; from-just)
2525
open import Data.Nat.Base as ℕ using (ℕ)
2626
open import Data.Product.Base using (Σ-syntax; _,_)
2727
open import Data.Vec.Base as Vec using (Vec ; lookup)
@@ -32,6 +32,7 @@ open import Data.List.Relation.Binary.Sublist.Heterogeneous
3232
open import Data.List.Relation.Binary.Sublist.Heterogeneous.Properties
3333
open import Function.Base using (_$_; case_of_)
3434

35+
open import Relation.Binary.Consequences using (dec⇒weaklyDec)
3536
open import Relation.Binary.PropositionalEquality.Core as ≡
3637
using (_≡_; _≗_; sym; cong; cong₂; subst₂)
3738
open import Relation.Binary.PropositionalEquality.Properties as ≡
@@ -124,8 +125,8 @@ private
124125

125126
-- Solver for items
126127
solveI : {n} (a b : Item n) Maybe (a ⊆I b)
127-
solveI (var k) (var l) = Maybe.map var $ decToMaybe (k Fin.≟ l)
128-
solveI (val a) (val b) = Maybe.map val $ decToMaybe (R? a b)
128+
solveI (var k) (var l) = Maybe.map var $ dec⇒weaklyDec Fin._≟_ k l
129+
solveI (val a) (val b) = Maybe.map val $ dec⇒weaklyDec R? a b
129130
solveI _ _ = nothing
130131

131132
-- Solver for linearised expressions

src/Data/Maybe/Base.agda

+14-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010

1111
module Data.Maybe.Base where
1212

13-
open import Level
13+
open import Level using (Level; Lift)
1414
open import Data.Bool.Base using (Bool; true; false; not)
1515
open import Data.Unit.Base using (⊤)
1616
open import Data.These.Base using (These; this; that; these)
1717
open import Data.Product.Base as Prod using (_×_; _,_)
18-
open import Function.Base using (const; _∘_; id)
19-
open import Relation.Nullary.Reflects using (invert)
20-
open import Relation.Nullary.Decidable.Core using (Dec; _because_)
18+
open import Function.Base using (_∘_; id; const)
19+
import Relation.Nullary.Decidable.Core as Dec
2120

2221
private
2322
variable
@@ -46,10 +45,6 @@ is-just nothing = false
4645
is-nothing : Maybe A Bool
4746
is-nothing = not ∘ is-just
4847

49-
decToMaybe : Dec A Maybe A
50-
decToMaybe ( true because [a]) = just (invert [a])
51-
decToMaybe (false because _ ) = nothing
52-
5348
-- A dependent eliminator.
5449

5550
maybe : {A : Set a} {B : Maybe A Set b}
@@ -137,3 +132,14 @@ thisM a = maybe′ (these a) (this a)
137132

138133
thatM : Maybe A B These A B
139134
thatM = maybe′ these that
135+
136+
------------------------------------------------------------------------
137+
-- DEPRECATED NAMES
138+
------------------------------------------------------------------------
139+
-- Please use the new names as continuing support for the old names is
140+
-- not guaranteed.
141+
142+
-- Version 2.1
143+
-- decToMaybe
144+
145+
open Dec using (decToMaybe) public

src/Relation/Binary/Consequences.agda

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
module Relation.Binary.Consequences where
1010

11-
open import Data.Maybe.Base using (just; nothing; decToMaybe)
12-
open import Data.Sum.Base as Sum using (inj₁; inj₂; [_,_]′)
11+
open import Data.Empty using (⊥-elim)
1312
open import Data.Product.Base using (_,_)
14-
open import Data.Empty.Irrelevant using (⊥-elim)
13+
open import Data.Sum.Base as Sum using (inj₁; inj₂; [_,_]′)
1514
open import Function.Base using (_∘_; _∘₂_; _$_; flip)
1615
open import Level using (Level)
1716
open import Relation.Binary.Core
1817
open import Relation.Binary.Definitions
19-
open import Relation.Nullary using (yes; no; recompute; ¬_)
20-
open import Relation.Nullary.Decidable.Core using (map′)
18+
open import Relation.Nullary.Negation.Core using (¬_)
19+
open import Relation.Nullary.Decidable.Core
20+
using (yes; no; recompute; map′; dec⇒maybe)
2121
open import Relation.Unary using (∁; Pred)
2222

2323
private
@@ -193,7 +193,7 @@ module _ {_R_ : Rel A ℓ₁} {Q : Rel A ℓ₂} where
193193
module _ {R : REL A B p} where
194194

195195
dec⇒weaklyDec : Decidable R WeaklyDecidable R
196-
dec⇒weaklyDec dec x y = decToMaybe (dec x y)
196+
dec⇒weaklyDec dec x y = dec⇒maybe (dec x y)
197197

198198
dec⇒recomputable : Decidable R Recomputable R
199199
dec⇒recomputable dec {a} {b} = recompute $ dec a b

src/Relation/Nullary/Decidable/Core.agda

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
module Relation.Nullary.Decidable.Core where
1313

14+
-- decToMaybe was deprecated in v2.1 #2330/#2336
15+
-- this can go through `Data.Maybe.Base` once that deprecation is fully done.
16+
open import Agda.Builtin.Maybe using (Maybe; just; nothing)
17+
1418
open import Agda.Builtin.Equality using (_≡_)
1519
open import Level using (Level)
1620
open import Data.Bool.Base using (Bool; T; false; true; not; _∧_; _∨_)
@@ -103,6 +107,13 @@ _→-dec_ : Dec A → Dec B → Dec (A → B)
103107
does (a? →-dec b?) = not (does a?) ∨ does b?
104108
proof (a? →-dec b?) = proof a? →-reflects proof b?
105109

110+
------------------------------------------------------------------------
111+
-- Relationship with Maybe
112+
113+
dec⇒maybe : Dec A Maybe A
114+
dec⇒maybe ( true because [a]) = just (invert [a])
115+
dec⇒maybe (false because _ ) = nothing
116+
106117
------------------------------------------------------------------------
107118
-- Relationship with Sum
108119

@@ -215,6 +226,12 @@ Please use ¬¬-excluded-middle instead."
215226

216227
-- Version 2.1
217228

229+
decToMaybe = dec⇒maybe
230+
{-# WARNING_ON_USAGE decToMaybe
231+
"Warning: decToMaybe was deprecated in v2.1.
232+
Please use Relation.Nullary.Decidable.Core.dec⇒maybe instead."
233+
#-}
234+
218235
fromDec = toSum
219236
{-# WARNING_ON_USAGE fromDec
220237
"Warning: fromDec was deprecated in v2.1.

0 commit comments

Comments
 (0)