Skip to content

Commit e926c7d

Browse files
Made Data.Container(.Any/.FreeMonad) safe by splitting out fixed points (#1513)
Co-authored-by: Guillaume ALLAIS <[email protected]>
1 parent 9070441 commit e926c7d

File tree

14 files changed

+222
-56
lines changed

14 files changed

+222
-56
lines changed

CHANGELOG.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ Non-backwards compatible changes
8282
`--safe` flag. For a full list of affected modules, refer to the
8383
relevant [commit](https://github.com/agda/agda-stdlib/pull/1465/files#diff-e1c0e3196e4cea6ff808f5d2906031a7657130e10181516206647b83c7014584R91-R131.)
8484

85-
* In order to keep `Data.Nat.Pseudorandom.LCG` safe, the function
85+
* In order to maintain the safety of `Data.Nat.Pseudorandom.LCG`, the function
8686
`stream` that relies on the newly unsafe `Codata` modules has
8787
been moved to the new module `Data.Nat.Pseudorandom.LCG.Unsafe`.
8888

89-
* In order to avoid the unsafe usage of the `--sized-types` in the
90-
`Codata.Musical` directory, the functions `fromMusical` and
91-
`toMusical` defined in:
89+
* In order to maintain the safety of the modules in the `Codata.Musical` directory,
90+
the functions `fromMusical` and `toMusical` defined in:
9291
```
9392
Codata.Musical.Colist
9493
Codata.Musical.Conat
@@ -99,6 +98,10 @@ Non-backwards compatible changes
9998
have been moved to a new module `Codata.Musical.Conversion` and renamed to
10099
`X.fromMusical` and `X.toMusical` for each of `Codata.Musical.X`.
101100

101+
* In order to maintain the safety of `Data.Container(.Indexed)`, the greatest fixpoint
102+
of containers, `ν`, has been moved from `Data.Container(.Indexed)` to a new module
103+
`Data.Container(.Indexed).Fixpoints.Guarded` which also re-exports the least fixpoint.
104+
102105
#### Other
103106

104107
* Replaced existing O(n) implementation of `Data.Nat.Binary.fromℕ` with a new O(log n)
@@ -151,6 +154,16 @@ New modules
151154
Data.List.Relation.Unary.Enumerates.Setoid.Properties
152155
```
153156

157+
* (Unsafe) sized W type:
158+
```
159+
Data.W.Sized
160+
```
161+
162+
* (Unsafe) container fixpoints:
163+
```
164+
Data.Container.Fixpoints.Sized
165+
```
166+
154167
Other minor additions
155168
---------------------
156169

GenerateEverything.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ sizedTypesModules = map modToFile
133133
, "Codata.Stream.Instances"
134134
, "Codata.Stream.Properties"
135135
, "Codata.Thunk"
136-
, "Data.Container"
137-
, "Data.Container.Any"
138-
, "Data.Container.FreeMonad"
136+
, "Data.Container.Fixpoints.Sized"
137+
, "Data.W.Sized"
139138
, "Data.Nat.PseudoRandom.LCG.Unsafe"
140139
, "Data.Tree.Binary.Show"
141140
, "Data.Tree.Rose"

src/Data/Container.agda

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
-- Containers, based on the work of Abbott and others
55
------------------------------------------------------------------------
66

7-
{-# OPTIONS --without-K --sized-types #-}
7+
{-# OPTIONS --without-K --safe #-}
88

9-
module Data.Container where
9+
open import Level using (Level; _⊔_)
10+
open import Data.W using (W)
1011

11-
open import Level using (_⊔_)
12-
open import Codata.M hiding (map)
13-
open import Data.W
14-
open import Size
12+
module Data.Container where
1513

1614
------------------------------------------------------------------------
1715
-- Re-exporting content to maintain backwards compatibility
@@ -41,10 +39,18 @@ module Morphism where
4139
open import Data.Container.Morphism
4240
using (id; _∘_) public
4341

44-
-- The least and greatest fixpoints of a container.
42+
private
43+
variable
44+
s p : Level
4545

46-
μ : {s p} Container s p Set (s ⊔ p)
46+
-- The least fixpoint of a container.
47+
48+
μ : Container s p Set (s ⊔ p)
4749
μ = W
4850

49-
ν : {s p} Container s p Set (s ⊔ p)
50-
ν C = M C ∞
51+
-- The greatest fixpoint of a container can be found
52+
-- in `Data.Container.Fixpoints.Guarded` as it relies
53+
-- on the `guardedness` flag.
54+
55+
-- You can find sized alternatives in `Data.Container.Fixpoints.Sized`
56+
-- as they rely on the unsafe flag `--sized-types`.

src/Data/Container/Any.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-- Data.Container.Relation.Unary.Any directly.
66
------------------------------------------------------------------------
77

8-
{-# OPTIONS --without-K --sized-types #-}
8+
{-# OPTIONS --without-K --safe #-}
99

1010
module Data.Container.Any where
1111

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Fixpoints for containers - using guardedness
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --safe --without-K --guardedness #-}
8+
9+
module Data.Container.Fixpoints.Guarded where
10+
11+
open import Level using (Level; _⊔_)
12+
open import Codata.Musical.M using (M)
13+
open import Data.Container using (Container)
14+
15+
private
16+
variable
17+
s p : Level
18+
19+
-- The least fixpoint can be found in `Data.Container`
20+
21+
open Data.Container public
22+
using (μ)
23+
24+
-- This lives in its own module due to its use of guardedness.
25+
26+
ν : Container s p Set (s ⊔ p)
27+
ν C = M C
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Sized fixpoints of containers, based on the work of Abbott and others
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --sized-types #-}
8+
9+
module Data.Container.Fixpoints.Sized where
10+
11+
open import Level
12+
open import Size
13+
open import Codata.M
14+
open import Data.W.Sized
15+
open import Data.Container hiding (μ) public
16+
17+
private
18+
variable
19+
s p : Level
20+
21+
-- The sized least and greatest fixpoints of a container.
22+
23+
μ : Container s p Size Set (s ⊔ p)
24+
μ = W
25+
26+
ν : Container s p Size Set (s ⊔ p)
27+
ν = M

src/Data/Container/FreeMonad.agda

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- The free monad construction on containers
55
------------------------------------------------------------------------
66

7-
{-# OPTIONS --without-K --sized-types #-}
7+
{-# OPTIONS --without-K --safe #-}
88

99
module Data.Container.FreeMonad where
1010

@@ -13,7 +13,7 @@ open import Data.Sum.Base using (inj₁; inj₂ ; [_,_]′)
1313
open import Data.Product
1414
open import Data.Container
1515
open import Data.Container.Combinator using (const; _⊎_)
16-
open import Data.W
16+
open import Data.W using (sup)
1717
open import Category.Monad
1818

1919
infixl 1 _⋆C_

src/Data/Container/Indexed.agda

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
-- (2006/9).
88
------------------------------------------------------------------------
99

10-
{-# OPTIONS --without-K --safe --guardedness #-}
10+
{-# OPTIONS --without-K --safe #-}
1111

1212
module Data.Container.Indexed where
1313

1414
open import Level
15-
open import Codata.Musical.M.Indexed
1615
open import Data.Product as Prod hiding (map)
1716
open import Data.W.Indexed
1817
open import Function.Base renaming (id to ⟨id⟩; _∘_ to _⟨∘⟩_)
@@ -37,9 +36,8 @@ I ▷ O = Container I O zero zero
3736

3837
-- The least and greatest fixpoint.
3938

40-
μ ν : {o c r} {O : Set o} Container O O c r Pred O _
39+
μ : {o c r} {O : Set o} Container O O c r Pred O _
4140
μ = W
42-
ν = M
4341

4442
-- An equivalence relation is defined in Data.Container.Indexed.WithK.
4543

src/Data/Container/Indexed/Combinator.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- Indexed container combinators
55
------------------------------------------------------------------------
66

7-
{-# OPTIONS --without-K --safe --guardedness #-}
7+
{-# OPTIONS --without-K --safe #-}
88

99
module Data.Container.Indexed.Combinator where
1010

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Greatest fixpoint for indexed containers - using guardedness
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --safe --without-K --guardedness #-}
8+
9+
module Data.Container.Indexed.Fixpoints.Guarded where
10+
11+
open import Level using (Level; _⊔_)
12+
open import Codata.Musical.M.Indexed using (M)
13+
open import Data.Container.Indexed using (Container)
14+
open import Relation.Unary using (Pred)
15+
16+
private
17+
variable
18+
o c r : Level
19+
O : Set o
20+
21+
22+
-- The least fixpoint can be found in `Data.Container`
23+
24+
open Data.Container.Indexed public
25+
using (μ)
26+
27+
-- This lives in its own module due to its use of guardedness.
28+
29+
ν : Container O O c r Pred O _
30+
ν = M

0 commit comments

Comments
 (0)