-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWith.agda
80 lines (63 loc) · 2.72 KB
/
With.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module With where
open import Reflection
open import Function using (_∘_ ; _$_ ; _∋_ ; id ; const)
open import Data.List
open import Data.Nat hiding (_+_)
open import Relation.Binary using (Setoid ; Decidable)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality hiding ( [_] ; subst )
open import Helper.CodeGeneration
{-# TERMINATING #-}
mutual
s_arg : (n : ℕ) -> (ℕ -> Term -> Term) -> Arg Term -> Arg Term
s_arg n f (arg i x) = arg i (s_term' n f x)
s_type : (n : ℕ) -> (ℕ -> Term -> Term) -> Type -> Type
s_type n f (el s t) = el s (s_term' n f t)
s_term : (n : ℕ) -> (ℕ -> Term -> Term) -> Term -> Term
s_term n f (var x args) = var x (map (s_arg n f) args)
s_term n f (con c args) = con c (map (s_arg n f) args)
s_term n f (def f₁ args) = def f₁ (map (s_arg n f) args)
s_term n f (lam v (abs s x)) = lam v (abs s (s_term' n f x))
s_term n f (pat-lam cs args) = pat-lam cs (map (s n arg f) args)
s_term n f (pi (arg i x) (abs s x₁)) = pi (arg i (s_type n f x)) (abs s (s_type n f x₁))
s_term n f t = t
s_term' : (n : ℕ) -> (ℕ -> Term -> Term) -> Term -> Term
s_term' n f t = f n (s_term n f t)
inc_debruijn_indices : Term -> Term
inc_debruijn_indices t = s_term' zero alg t
where
alg : ℕ -> Term -> Term
alg n (var x args) = var (suc x) args
alg n t2 = t2
subst : Term -> Term -> Term -> Term
subst t ti to = s_term' zero alg t
where
alg : ℕ -> Term -> Term
alg n ti1 with ti Reflection.≟ ti1
alg n ti1 | yes p = to
alg n ti1 | no ¬p = ti1
getType : {T : Set} -> (t : T) -> Term
getType {T} t = quoteTerm T
with' : Term -> Term -> Term
with' w l = quote-goal (abs "g" lam_body)
where
sub_term = def (quote subst) ( (a $ var 1 []) ∷ (a $ w) ∷ (a $ quote-term $ var 0 []) ∷ [] )
lam_type_q = unquote-term sub_term []
lam_type = pi (a $ t0 unknown) (abs "i" $ t0 $ lam_type_q)
lam_body = def (quote _$_) ((a $ lam_type ∋-t l) ∷ (a $ inc_debruijn_indices $ unquote-term w []) ∷ [])
postulate
A : Set
_+_ : A → A → A
T : A → Set
mkT : ∀ x → T x
P : ∀ x → T x → Set
-- the type A of the with argument has no free variables, so the with
-- argument will come first
f₁ : (x y : A) (t : T (x + y)) → T (x + y)
f₁ x y t with x + y
f₁ x y t | w = mkT w
f₂ : (x y : A) → T (x + y)
f₂ x y = unquote (with' (quoteTerm (quoteTerm (x + y))) (quoteTerm (\w -> mkT w)))
-- def (quote inc_var_indices) [ a $ var 1 [] ] --
-- sub_term = def (quote subst) ( (a $ var 1 []) ∷ (a $ w) ∷ (a $ (quote-term (var 0 []))) ∷ [] )
-- lam_type = pi (a $ t0 $ (def (quote _≡_) ((a $ var 3 []) ∷ (a $ var 2 []) ∷ []))) (abs "i" $ t0 $ lam_type_q)