-
Notifications
You must be signed in to change notification settings - Fork 0
/
cockett.agda
63 lines (49 loc) · 1.92 KB
/
cockett.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module cockett where
open import Data.Product
open import Data.Product.Properties as Σ
open import Data.Sum
open import Data.Sum.Properties as ⊎
open import Data.Empty
open import Data.Unit
open import Data.Unit.Properties as ⊤
open import Relation.Binary.PropositionalEquality hiding (Extensionality)
open import Relation.Nullary
open import Axiom.Extensionality.Propositional
open import Level renaming (zero to lzero; suc to lsuc)
postulate
funext : Extensionality lzero lzero
dec→≠ : {A : Set} → (f g : A → ⊥) → Dec (f ≡ g)
dec→≠ {A} f g = yes (funext λ x → ⊥-elim (f x))
record IC (X Y : Set) : Set1 where
constructor mkIC
field
Sh : Y -> Set
Pos : (y : Y) → Sh y → Set
dec : (y : Y) → (s : Sh y) → (p q : Pos y s) → Dec (p ≡ q)
next : (y : Y) → (s : Sh y) → Pos y s → X
record IC' (X : Set) : Set1 where
constructor mkIC
field
Sh : Set
Pos : Sh → Set
dec : (s : Sh) → (p q : Pos s) → Dec (p ≡ q)
next : (s : Sh) → Pos s → X
IC-old : {X Y : Set} → Set1
IC-old {X} {Y} = Y -> IC' X
⟦_⟧ : {X Y : Set} → IC X Y → (X → Set) → (Y → Set)
⟦ mkIC S P dec n ⟧ Q y = Σ[ s ∈ S y ] ((p : P y s) → Q (n y s p))
Diff : {X Y : Set} → IC X Y → IC (X ⊎ X) Y
Diff (mkIC S P dec n) = mkIC
(λ y → Σ (S y) (P y))
(λ y (s , p) → ⊤ ⊎ Σ[ q ∈ P y s ] (p ≡ q → ⊥))
(λ y (s , p) → ⊎.≡-dec ⊤._≟_ (Σ.≡-dec (dec y s) dec→≠))
(λ y (s , p) → Data.Sum.map (λ tt → n y s p) (λ (q , q≠p) → n y s q))
Dec-to-⊎ : {P : Set} → Dec P → P ⊎ (P → ⊥)
Dec-to-⊎ (yes p) = inj₁ p
Dec-to-⊎ (no ¬p) = inj₂ ¬p
Diff-old : {X Y : Set} → IC X Y → IC (X ⊎ X) Y
Diff-old (mkIC S P dec n) = mkIC
(λ y → Σ (S y) (P y))
(λ y (s , p) → P y s)
(λ y (s , p) → dec y s)
(λ y (s , p) q → Data.Sum.map (λ _ → n y s p) (λ _ → n y s q) (Dec-to-⊎ (dec y s p q)))