Skip to content

Commit a5d4a19

Browse files
authored
[ refactor ] Make Data.Irrelevant.Irrelevant a proper Monad (#2977)
* [ refactor ] Make `Data.Irrelevant.Irrelevant` a proper `Monad` * fix: names
1 parent 0af0768 commit a5d4a19

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Non-backwards compatible changes
2424
Minor improvements
2525
------------------
2626

27+
* The function `Data.Irrelevant._>>=_` now has the correct type for a 'bind'
28+
operation of a `Monad`, by moving the property `irrelevant-recompute`
29+
from `Relation.Nullary.Recomputable` to `Data.Irrelevant` as `recompute`,
30+
and re-exporting it from the former module with the old name. This should
31+
be backwards compatible.
32+
2733
* The function `Data.Nat.LCG.step` is now a manifest field of the record type
2834
`Generator`, as per the discussion on #2936 and upstream issues/PRs. This is
2935
consistent with a minimal API for such LCGs, and should be backwards compatible.
@@ -93,6 +99,13 @@ Deprecated names
9399
¬∀⟶∃¬- ↦ ¬∀⇒∃¬
94100
```
95101

102+
* In `Data.Irrelevant`:
103+
```agda
104+
λ∙⁻ : (.A → B) → Irrelevant A → B
105+
λ∙⁺ : (Irrelevant A → B) → .A → B
106+
recompute : Recomputable (Irrelevant A)
107+
```
108+
96109
* In `Data.List.Fresh.Membership.Setoid.Properties`:
97110
```agda
98111
≈-subst-∈ ↦ ∈-resp-≈

src/Data/Irrelevant.agda

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
module Data.Irrelevant where
1515

1616
open import Level using (Level)
17+
open import Relation.Nullary.Recomputable.Core using (Recomputable)
1718

1819
private
1920
variable
@@ -31,7 +32,23 @@ record Irrelevant (A : Set a) : Set a where
3132
open Irrelevant public
3233

3334
------------------------------------------------------------------------
34-
-- Algebraic structure: Functor, Appplicative and Monad-like
35+
-- Relationship with the . modality: wrapped/unwrapped abstraction
36+
37+
λ∙⁻ : (.A B) Irrelevant A B
38+
λ∙⁻ f [ a ] = f a
39+
{-# INLINE λ∙⁻ #-}
40+
41+
λ∙⁺ : (Irrelevant A B) .A B
42+
λ∙⁺ f a = f [ a ]
43+
{-# INLINE λ∙⁺ #-}
44+
45+
-- Irrelevant types are Recomputable
46+
47+
recompute : Recomputable (Irrelevant A)
48+
irrelevant (recompute [ a ]) = a
49+
50+
------------------------------------------------------------------------
51+
-- Algebraic structure: Functor, Appplicative and Monad
3552

3653
map : (A B) Irrelevant A Irrelevant B
3754
map f [ a ] = [ f a ]
@@ -44,8 +61,8 @@ _<*>_ : Irrelevant (A → B) → Irrelevant A → Irrelevant B
4461
[ f ] <*> [ a ] = [ f a ]
4562

4663
infixl 1 _>>=_
47-
_>>=_ : Irrelevant A (.A Irrelevant B) Irrelevant B
48-
[ a ] >>= f = f a
64+
_>>=_ : Irrelevant A (A Irrelevant B) Irrelevant B
65+
[ a ] >>= f = recompute (f a)
4966

5067
------------------------------------------------------------------------
5168
-- Other functions

src/Relation/Nullary/Recomputable.agda

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
module Relation.Nullary.Recomputable where
1010

1111
open import Data.Empty using (⊥)
12-
open import Data.Irrelevant using (Irrelevant; irrelevant; [_])
1312
open import Data.Product.Base using (_×_; _,_; proj₁; proj₂)
1413
open import Level using (Level)
1514
open import Relation.Nullary.Negation.Core using (¬_)
@@ -21,20 +20,17 @@ private
2120
B : Set b
2221

2322
------------------------------------------------------------------------
24-
-- Re-export
23+
-- Re-export core definitions
2524

2625
open import Relation.Nullary.Recomputable.Core public
2726

28-
29-
------------------------------------------------------------------------
30-
-- Constructions
31-
3227
-- Irrelevant types are Recomputable
3328

34-
irrelevant-recompute : Recomputable (Irrelevant A)
35-
irrelevant (irrelevant-recompute [ a ]) = a
29+
open import Data.Irrelevant public
30+
using () renaming (recompute to irrelevant-recompute)
3631

37-
-- Corollary: so too is ⊥
32+
------------------------------------------------------------------------
33+
-- Constructions
3834

3935
⊥-recompute : Recomputable ⊥
4036
⊥-recompute = irrelevant-recompute

0 commit comments

Comments
 (0)