Skip to content

Commit 0d529ce

Browse files
committed
Adapted Dominique's patches to my taste. Made more things polymorphic.
+ Some definitions were made less polymorphic (one level argument instead of several) in order to avoid code duplication.
1 parent 62edece commit 0d529ce

File tree

10 files changed

+305
-309
lines changed

10 files changed

+305
-309
lines changed

.boring

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
^dist($|/)
55
^html($|/)
66
^Everything\.agda$
7-
dist

LICENCE

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Copyright (c) 2007-2011 Nils Anders Danielsson, Ulf Norell, Shin-Cheng
22
Mu, Samuel Bronson, Dan Doel, Patrik Jansson, Liang-Ting Chen,
33
Jean-Philippe Bernardy, Andrés Sicard-Ramírez, Nicolas Pouillard,
4-
Darin Morrison, Peter Berry, Daniel Brown, Simon Foster, Dominique Devriese
4+
Darin Morrison, Peter Berry, Daniel Brown, Simon Foster, Dominique
5+
Devriese
56

67
Permission is hereby granted, free of charge, to any person obtaining a
78
copy of this software and associated documentation files (the

README.agda

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ module README where
55
--
66
-- Author: Nils Anders Danielsson, with contributions from
77
-- Jean-Philippe Bernardy, Peter Berry, Samuel Bronson, Daniel Brown,
8-
-- Liang-Ting Chen, Dan Doel, Simon Foster, Patrik Jansson, Darin
9-
-- Morrison, Shin-Cheng Mu, Ulf Norell, Nicolas Pouillard, Andrés
10-
-- Sicard-Ramírez and Dominique Devriese
8+
-- Liang-Ting Chen, Dominique Devriese, Dan Doel, Simon Foster, Patrik
9+
-- Jansson, Darin Morrison, Shin-Cheng Mu, Ulf Norell, Nicolas
10+
-- Pouillard and Andrés Sicard-Ramírez
1111
------------------------------------------------------------------------
1212

1313
-- Note that the development version of the library often requires the

src/Data/List/All.agda

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
------------------------------------------------------------------------
22
-- Lists where all elements satisfy a given property
33
------------------------------------------------------------------------
4+
45
{-# OPTIONS --universe-polymorphism #-}
56

67
module Data.List.All where
78

8-
open import Level
9-
open import Function
109
open import Data.List as List hiding (map; all)
1110
open import Data.List.Any as Any using (here; there)
1211
open Any.Membership-≡ using (_∈_; _⊆_)
12+
open import Function
13+
open import Level
1314
open import Relation.Nullary
1415
import Relation.Nullary.Decidable as Dec
1516
open import Relation.Unary using () renaming (_⊆_ to _⋐_)
@@ -19,17 +20,20 @@ open import Relation.Binary.PropositionalEquality
1920

2021
infixr 5 _∷_
2122

22-
data All {p a} {A : Set a} (P : A Set p) : List A Set (p ⊔ a) where
23+
data All {a p} {A : Set a}
24+
(P : A Set p) : List A Set (p ⊔ a) where
2325
[] : All P []
2426
_∷_ : {x xs} (px : P x) (pxs : All P xs) All P (x ∷ xs)
2527

26-
head : {p a} {A : Set a} {P : A Set p} {x xs} All P (x ∷ xs) P x
28+
head : {a p} {A : Set a} {P : A Set p} {x xs}
29+
All P (x ∷ xs) P x
2730
head (px ∷ pxs) = px
2831

29-
tail : {p a} {A : Set a} {P : A Set p} {x xs} All P (x ∷ xs) All P xs
32+
tail : {a p} {A : Set a} {P : A Set p} {x xs}
33+
All P (x ∷ xs) All P xs
3034
tail (px ∷ pxs) = pxs
3135

32-
lookup : {p a} {A : Set a} {P : A Set p} {xs : List A}
36+
lookup : {a p} {A : Set a} {P : A Set p} {xs : List A}
3337
All P xs ( {x : A} x ∈ xs P x)
3438
lookup [] ()
3539
lookup (px ∷ pxs) (here refl) = px
@@ -45,7 +49,7 @@ map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} →
4549
map g [] = []
4650
map g (px ∷ pxs) = g px ∷ map g pxs
4751

48-
all : {p a} {A : Set a} {P : A Set p}
52+
all : {a p} {A : Set a} {P : A Set p}
4953
( x Dec (P x)) (xs : List A) Dec (All P xs)
5054
all p [] = yes []
5155
all p (x ∷ xs) with p x

src/Data/List/All/Properties.agda

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
------------------------------------------------------------------------
22
-- Properties relating All to various list functions
33
------------------------------------------------------------------------
4+
45
{-# OPTIONS --universe-polymorphism #-}
56

67
module Data.List.All.Properties where
@@ -19,20 +20,23 @@ open import Relation.Unary using () renaming (_⊆_ to _⋐_)
1920

2021
-- Functions can be shifted between the predicate and the list.
2122

22-
All-map : {a b p} {A : Set a} {B : Set b} {P : B Set p} {f : A B} {xs}
23+
All-map : {a b p} {A : Set a} {B : Set b} {P : B Set p}
24+
{f : A B} {xs}
2325
All (P ∘ f) xs All P (List.map f xs)
2426
All-map [] = []
2527
All-map (p ∷ ps) = p ∷ All-map ps
2628

27-
map-All : {a b p} {A : Set a} {B : Set b} {P : B Set p} {f : A B} {xs}
29+
map-All : {a b p} {A : Set a} {B : Set b} {P : B Set p}
30+
{f : A B} {xs}
2831
All P (List.map f xs) All (P ∘ f) xs
2932
map-All {xs = []} [] = []
3033
map-All {xs = _ ∷ _} (p ∷ ps) = p ∷ map-All ps
3134

3235
-- A variant of All.map.
3336

34-
gmap : {a b p q} {A : Set a} {B : Set b} {P : A Set p} {Q : B Set q}
35-
{f : A B}
37+
gmap : {a b p q}
38+
{A : Set a} {B : Set b} {P : A Set p} {Q : B Set q}
39+
{f : A B}
3640
P ⋐ Q ∘ f All P ⋐ All Q ∘ List.map f
3741
gmap g = All-map ∘ All.map g
3842

src/Data/List/Any.agda

+28-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
------------------------------------------------------------------------
22
-- Lists where at least one element satisfies a given property
33
------------------------------------------------------------------------
4+
45
{-# OPTIONS --universe-polymorphism #-}
56

67
module Data.List.Any where
@@ -26,7 +27,8 @@ open import Relation.Binary.PropositionalEquality as PropEq
2627

2728
-- Any P xs means that at least one element in xs satisfies P.
2829

29-
data Any {a p : Level} {A : Set a} (P : A Set p) : List A Set (a ⊔ p) where
30+
data Any {a p} {A : Set a}
31+
(P : A Set p) : List A Set (a ⊔ p) where
3032
here : {x xs} (px : P x) Any P (x ∷ xs)
3133
there : {x xs} (pxs : Any P xs) Any P (x ∷ xs)
3234

@@ -39,14 +41,14 @@ map g (there pxs) = there (map g pxs)
3941

4042
-- If the head does not satisfy the predicate, then the tail will.
4143

42-
tail : {a} {A : Set a} {x : A} {xs : List A} {P : A Set}
44+
tail : {a p} {A : Set a} {x : A} {xs : List A} {P : A Set p}
4345
¬ P x Any P (x ∷ xs) Any P xs
4446
tail ¬px (here px) = ⊥-elim (¬px px)
4547
tail ¬px (there pxs) = pxs
4648

4749
-- Decides Any.
4850

49-
any : {a : Level} {A : Set a} {P : A Set}
51+
any : {a p} {A : Set a} {P : A Set p}
5052
( x Dec (P x)) (xs : List A) Dec (Any P xs)
5153
any p [] = no λ()
5254
any p (x ∷ xs) with p x
@@ -55,7 +57,8 @@ any p (x ∷ xs) | no ¬px = Dec.map′ there (tail ¬px) (any p xs)
5557

5658
-- index x∈xs is the list position (zero-based) which x∈xs points to.
5759

58-
index : {a} {A : Set a} {P : A Set} {xs} Any P xs Fin (List.length xs)
60+
index : {a p} {A : Set a} {P : A Set p} {xs}
61+
Any P xs Fin (List.length xs)
5962
index (here px) = zero
6063
index (there pxs) = suc (index pxs)
6164

@@ -72,7 +75,8 @@ module Membership {c ℓ : Level} (S : Setoid c ℓ) where
7275
-- If a predicate P respects the underlying equality then Any P
7376
-- respects the list equality.
7477

75-
lift-resp : {P} P Respects _≈_ Any P Respects _≋_
78+
lift-resp : {p} {P : A Set p}
79+
P Respects _≈_ Any P Respects _≋_
7680
lift-resp resp [] ()
7781
lift-resp resp (x≈y ∷ xs≈ys) (here px) = here (resp x≈y px)
7882
lift-resp resp (x≈y ∷ xs≈ys) (there pxs) =
@@ -82,7 +86,7 @@ module Membership {c ℓ : Level} (S : Setoid c ℓ) where
8286

8387
infix 4 _∈_ _∉_
8488

85-
_∈_ : A List A Set (c ⊔ ℓ)
89+
_∈_ : A List A Set _
8690
x ∈ xs = Any (_≈_ x) xs
8791

8892
_∉_ : A List A Set _
@@ -126,18 +130,20 @@ module Membership {c ℓ : Level} (S : Setoid c ℓ) where
126130

127131
-- A variant of List.map.
128132

129-
map-with-∈ : {b} {B : Set b} (xs : List A) ( {x} x ∈ xs B) List B
133+
map-with-∈ : {b} {B : Set b}
134+
(xs : List A) ( {x} x ∈ xs B) List B
130135
map-with-∈ [] f = []
131136
map-with-∈ (x ∷ xs) f = f (here S.refl) ∷ map-with-∈ xs (f ∘ there)
132137

133138
-- Finds an element satisfying the predicate.
134139

135-
find : {p} {P : A Set p} {xs} Any P xs λ x x ∈ xs × P x
140+
find : {p} {P : A Set p} {xs}
141+
Any P xs λ x x ∈ xs × P x
136142
find (here px) = (_ , here S.refl , px)
137143
find (there pxs) = Prod.map id (Prod.map there id) (find pxs)
138144

139-
lose : {p} {P : A Set p} {x xs} P Respects _≈_
140-
x ∈ xs P x Any P xs
145+
lose : {p} {P : A Set p} {x xs}
146+
P Respects _≈_ x ∈ xs P x Any P xs
141147
lose resp x∈xs px = map (flip resp px) x∈xs
142148

143149
-- The code above instantiated (and slightly changed) for
@@ -149,12 +155,13 @@ module Membership-≡ where
149155
open module M {a} {A : Set a} = Membership (PropEq.setoid A) public
150156
hiding (lift-resp; lose; ⊆-preorder; module ⊆-Reasoning)
151157

152-
lose : {a p} {A : Set a} {P : A Set p} {x xs} x ∈ xs P x Any P xs
158+
lose : {a p} {A : Set a} {P : A Set p} {x xs}
159+
x ∈ xs P x Any P xs
153160
lose {P = P} = M.lose (PropEq.subst P)
154161

155162
-- _⊆_ is a preorder.
156163

157-
⊆-preorder : {a : Level} Set a Preorder _ _ _
164+
⊆-preorder : {a} Set a Preorder _ _ _
158165
⊆-preorder A = Ind.InducedPreorder₂ (PropEq.setoid (List A)) _∈_
159166
(PropEq.subst (_∈_ _))
160167

@@ -163,17 +170,17 @@ module Membership-≡ where
163170
open Inv public
164171
using (Kind) renaming (equivalent to set; inverse to bag)
165172

166-
[_]-Equality : Kind {a : Level} Set a Setoid _ _
173+
[_]-Equality : Kind {a} Set a Setoid _ _
167174
[ k ]-Equality A = Inv.InducedEquivalence₂ k (_∈_ {A = A})
168175

169176
infix 4 _≈[_]_
170177

171-
_≈[_]_ : {a : Level} {A : Set a} List A Kind List A Set _
172-
_≈[_]_ {a} {A} xs k ys = Setoid._≈_ ([ k ]-Equality A) xs ys
178+
_≈[_]_ : {a} {A : Set a} List A Kind List A Set _
179+
_≈[_]_ {A = A} xs k ys = Setoid._≈_ ([ k ]-Equality A) xs ys
173180

174181
-- Bag equality implies set equality.
175182

176-
bag-=⇒set-= : {a : Level} {A : Set a} {xs ys : List A}
183+
bag-=⇒set-= : {a} {A : Set a} {xs ys : List A}
177184
xs ≈[ bag ] ys xs ≈[ set ] ys
178185
bag-=⇒set-= xs≈ys = Inv.⇿⇒ xs≈ys
179186

@@ -182,17 +189,17 @@ module Membership-≡ where
182189
module ⊆-Reasoning where
183190
import Relation.Binary.PreorderReasoning as PreR
184191
private
185-
open module PR {A : Set} = PreR (⊆-preorder A) public
192+
open module PR {a} {A : Set a} = PreR (⊆-preorder A) public
186193
renaming (_∼⟨_⟩_ to _⊆⟨_⟩_; _≈⟨_⟩_ to _≡⟨_⟩_)
187194

188195
infixr 2 _≈⟨_⟩_
189196
infix 1 _∈⟨_⟩_
190197

191-
_∈⟨_⟩_ : {A : Set} x {xs ys : List A}
198+
_∈⟨_⟩_ : {a} {A : Set a} x {xs ys : List A}
192199
x ∈ xs xs IsRelatedTo ys x ∈ ys
193200
x ∈⟨ x∈xs ⟩ xs⊆ys = (begin xs⊆ys) x∈xs
194201

195-
_≈⟨_⟩_ : {k} {A : Set} xs {ys zs : List A}
202+
_≈⟨_⟩_ : {k a} {A : Set a} xs {ys zs : List A}
196203
xs ≈[ k ] ys ys IsRelatedTo zs xs IsRelatedTo zs
197204
xs ≈⟨ xs≈ys ⟩ ys≈zs =
198205
xs ⊆⟨ _⟨$⟩_ (Equivalent.to (Inv.⇒⇔ xs≈ys)) ⟩ ys≈zs
@@ -202,5 +209,6 @@ module Membership-≡ where
202209

203210
-- If any element satisfies P, then P is satisfied.
204211

205-
satisfied : {a p} {A : Set a} {P : A Set p} {xs} Any P xs ∃ P
212+
satisfied : {a p} {A : Set a} {P : A Set p} {xs}
213+
Any P xs ∃ P
206214
satisfied = Prod.map id Prod.proj₂ ∘ Membership-≡.find

0 commit comments

Comments
 (0)