1
1
{-# OPTIONS --safe #-}
2
- open import Generics.Prelude hiding (lookup; _≟_)
3
- open import Generics.HasDesc
4
- open import Generics.Desc
5
- open import Generics.Telescope
6
- open import Generics.Reflection
7
-
8
- open import Generics.Constructions.Show as Show
9
- open import Generics.Constructions.Case
10
- open import Generics.Constructions.Elim
11
- open import Generics.Constructions.Fold
12
- open import Generics.Constructions.Cong
13
- open import Generics.Helpers
14
- -- open import Generics.Constructions.DecEq
2
+
3
+ module Parametrized where
4
+
5
+ open import Generics
6
+
7
+ open import Agda.Primitive
8
+ open import Function.Base
9
+ open import Data.Nat.Base hiding (pred)
10
+ open import Data.Fin.Base hiding (pred; _+_)
11
+ open import Data.List.Base hiding (sum; length)
15
12
16
13
open import Relation.Nullary
17
14
open import Relation.Nullary.Decidable as Decidable
18
15
open import Relation.Binary.HeterogeneousEquality.Core using (_≅_; refl)
16
+ open import Relation.Binary.PropositionalEquality
19
17
20
18
open import Data.String hiding (show; _≟_; length)
21
19
open import Data.Maybe.Base
22
- open import Data.Nat.Base using (_*_)
23
-
24
-
25
- module Parametrized where
26
-
27
- open Show.Show ⦃...⦄
28
20
29
21
30
22
module Nat where
@@ -36,11 +28,13 @@ module Nat where
36
28
---------------------------
37
29
-- Deriving the eliminator
38
30
31
+ elimℕ = deriveElim natD
32
+
39
33
plus : ℕ → ℕ → ℕ
40
- plus n = elim (const ℕ) n (const suc)
34
+ plus n = elimℕ (const ℕ) n suc
41
35
42
36
mult : ℕ → ℕ → ℕ
43
- mult n = elim (const ℕ) 0 (const ( plus n) )
37
+ mult n = elimℕ (const ℕ) 0 (plus n)
44
38
45
39
-- things defined with the eliminator reduce properly on open terms
46
40
@@ -93,23 +87,23 @@ module Nat where
93
87
congℕ = deriveCong natD
94
88
95
89
ze≅ze : 0 ≅ 0
96
- ze≅ze = congℕ Fin. zero
90
+ ze≅ze = congℕ zero
97
91
98
92
su≅su : ∀ {n m} → n ≅ m → suc n ≅ suc m
99
93
su≅su = congℕ (suc zero)
100
94
101
-
102
95
-------------------------------
103
96
-- Deriving decidable equality
104
97
105
- -- instance decℕ : DecEq ℕ
106
- -- decℕ = deriveDecEq natD
98
+ instance decℕ : DecEq ℕ
99
+ decℕ = deriveDecEq natD
107
100
108
- -- _ : 3 ≟ 3 ≡ yes refl
109
- -- _ = refl
101
+ _ : 3 ≟ 3 ≡ yes refl
102
+ _ = refl
103
+
104
+ _ : 3 ≟ 2 ≡ no _
105
+ _ = refl
110
106
111
- -- _ : 3 ≟ 2 ≡ no _
112
- -- _ = refl
113
107
114
108
module ListDemo where
115
109
@@ -134,39 +128,40 @@ module ListDemo where
134
128
mul : list ℕ → ℕ
135
129
mul = foldList 1 _*_
136
130
137
- module Vek where
131
+
132
+ module Vec where
138
133
private variable A : Set
139
134
n : ℕ
140
135
141
- data Vek (A : Set ) : ℕ → Set where
142
- nil : Vek A 0
143
- cons : ∀ {n} → A → Vek A n → Vek A (suc n)
136
+ data Vec (A : Set ) : ℕ → Set where
137
+ nil : Vec A 0
138
+ cons : ∀ {n} → A → Vec A n → Vec A (suc n)
144
139
145
140
instance
146
- vekD : HasDesc Vek
147
- vekD = deriveDesc Vek
141
+ vekD : HasDesc Vec
142
+ vekD = deriveDesc Vec
148
143
149
144
---------------------------
150
145
-- Deriving the eliminator
151
146
152
- elimVek = deriveElim vekD
147
+ elimVec = deriveElim vekD
153
148
154
- length : Vek A n → ℕ
155
- length = elimVek (const ℕ) 0 (λ x xs n → suc n )
149
+ length : Vec A n → ℕ
150
+ length = elimVec (const ℕ) 0 (const suc)
156
151
157
- length0 : length (nil {A = A }) ≡ 0
152
+ length0 : length (nil {A}) ≡ 0
158
153
length0 = refl
159
154
160
- lengthP : (x : Vek A n) → length x ≡ n
161
- lengthP = elimVek (λ {n} x → length x ≡ n) refl λ x xs Pxs → cong suc Pxs
155
+ lengthP : (x : Vec A n) → length x ≡ n
156
+ lengthP = elimVec (λ {n} x → length x ≡ n) refl (const ( cong suc))
162
157
163
158
---------------------------
164
159
-- Deriving fold
165
160
166
- foldVek = deriveFold vekD
161
+ foldVec = deriveFold vekD
167
162
168
- vekToList : ∀ {A n} → Vek A n → List A
169
- vekToList = foldVek [] _∷_
163
+ vekToList : ∀ {A n} → Vec A n → List A
164
+ vekToList = foldVec [] _∷_
170
165
171
166
-----------------------
172
167
-- Deriving congruence
@@ -176,7 +171,7 @@ module Vek where
176
171
[]≅[] : ∀ {A} → nil {A} ≅ nil {A}
177
172
[]≅[] = congV zero
178
173
179
- cong-cons : ∀ {A n} {x y : A} → x ≅ y → {xs ys : Vek A n} → xs ≅ ys
174
+ cong-cons : ∀ {A n} {x y : A} → x ≅ y → {xs ys : Vec A n} → xs ≅ ys
180
175
→ cons x xs ≅ cons y ys
181
176
cong-cons = congV (suc zero) refl
182
177
@@ -196,14 +191,15 @@ module WType where
196
191
-- Deriving the eliminator
197
192
198
193
elimW : (Pr : W A B → Set c)
199
- → (∀ x g → (∀ y → Pr (g y)) → Pr (node x g) )
194
+ → (∀ x {g} → (∀ y → Pr (g y)) → Pr (node x g) )
200
195
→ ∀ x → Pr x
201
196
elimW = deriveElim wD
202
197
203
198
elimW-node
204
199
: {Pr : W A B → Set c}
205
- (M : ∀ x g → (∀ y → Pr (g y)) → Pr (node x g) )
206
- → ∀ {x g} → elimW Pr M (node x g) ≡ M x g (λ y → elimW Pr M (g y))
200
+ (M : ∀ x {g} → (∀ y → Pr (g y)) → Pr (node x g) )
201
+ → ∀ {x g}
202
+ → elimW Pr M (node x g) ≡ M x (λ y → elimW Pr M (g y))
207
203
elimW-node M = refl
208
204
209
205
@@ -230,6 +226,5 @@ module Irrelevance where
230
226
instance showSquash : ∀ {A} → Show (Squash A)
231
227
showSquash = deriveShow squashD
232
228
233
- -- Indeed, we use the argument name when printing irrelevant args
234
- _ : show (squash 3 ) ≡ "squash (.x)"
229
+ _ : show (squash 3 ) ≡ "squash (._)"
235
230
_ = refl
0 commit comments