Skip to content

Commit ea64830

Browse files
committed
added Adrian's comments to Notes.md
1 parent 7c1d4d7 commit ea64830

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

Notes.md

+72
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,75 @@ The following comments were collected on the Agda mailing list.
281281
* ƛ \Gl-
282282
*\.
283283

284+
## Adrian's comments from MeetUp
285+
286+
Adrian King
287+
I think we've finally gone through the whole book now up through chapter Properties, and we've come up with just three places where we thought the book could have done a better job of preparing us for the exercises.
288+
289+
Starting from the end of the book:
290+
291+
* Chapter Quantifiers, exercise Bin-isomorphism:
292+
293+
In the to∘from case, we want to show that:
294+
295+
⟨ to (from x) , toCan {from x} ⟩ ≡ ⟨ x , canX ⟩
296+
297+
I found myself wanting to use a general lemma like:
298+
299+
```
300+
exEq :
301+
∀ {A : Set} {x y : A} {p : A → Set} {px : p x} {py : p y} →
302+
x ≡ y →
303+
px ≡ py →
304+
⟨ x , px ⟩ ≡ ⟨ y , py ⟩
305+
exEq refl refl = refl
306+
```
307+
308+
which is in some sense true, but in Agda it doesn't typecheck, because Agda can't see that px's type and py's type are the same. My solution made explicit use of heterogeneous equality.
309+
310+
I realize there are ways to solve this that don't explicitly use heterogeneous equality, but the surprise factor of the exercise might have been lower if heterogeneous equality had been mentioned by that point, perhaps in the Equality chapter.
311+
312+
* Chapter Quantifiers, exercise ∀-×:
313+
314+
I assume the intended solution looks something like:
315+
316+
```
317+
∀-× : ∀ {B : Tri → Set} → ((x : Tri) → B x) ≃ (B aa × B bb × B cc)
318+
∀-× = record {
319+
to = λ f → ⟨ f aa , ⟨ f bb , f cc ⟩ ⟩ ;
320+
from = λ{ ⟨ baa , ⟨ bbb , bcc ⟩ ⟩ → λ{ aa → baa ; bb → bbb ; cc → bcc } } ;
321+
from∘to = λ f → extensionality λ{ aa → refl ; bb → refl ; cc → refl } ;
322+
to∘from = λ{ y → refl } }
323+
```
324+
325+
but it doesn't typecheck; in the extensionality presented earlier (in chapter Isomorphism), type B is not dependent on type A, but it needs to be here. Agda's error message is sufficiently baffling here that you might want to warn people that they need a dependent version of extensionality, something like:
326+
327+
```
328+
Extensionality : (a b : Level) → Set _
329+
Extensionality a b =
330+
{A : Set a} {B : A → Set b} {f g : (x : A) → B x} →
331+
(∀ x → f x ≡ g x) → f ≡ g
332+
333+
postulate
334+
exten : ∀ {a b} → Extensionality a b
335+
```
336+
337+
* Chapter Relations, exercise Bin-predicates:
338+
339+
I made use here of the inspect idiom, in Aaron Stump's variant, which is syntactically more convenient:
340+
341+
```
342+
keep : ∀ {ℓa} → {a : Set ℓa} → (x : a) → Σ a (λ y → y ≡ x)
343+
keep x = x , refl
344+
```
345+
346+
Pattern matching on keep m, where m is some complicated term, lets you keep around an equality between the original term and the pattern matched, which is often convenient, as in:
347+
348+
```
349+
roundTripTwice {x} onex with keep (from x)
350+
roundTripTwice {x} onex | zero , eq with oneIsMoreThanZero onex
351+
roundTripTwice {x} onex | zero , eq | 0<fromx rewrite sym eq =
352+
⊥-elim (not0<0 0<fromx)
353+
roundTripTwice {x} onex | suc n , eq rewrite sym eq | toTwiceSuc {n} |
354+
cong x0_ (sym (roundTrip (one onex))) | sym eq = refl
355+
```

0 commit comments

Comments
 (0)