Subst.agda 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. module Subst (Gnd : Set)(U : Set)(El : U -> Set) where
  2. open import Basics
  3. open import Pr
  4. open import Nom
  5. import Kind
  6. open Kind Gnd U El
  7. import Cxt
  8. open Cxt Kind
  9. import Loc
  10. open Loc Kind
  11. import Term
  12. open Term Gnd U El
  13. import Shift
  14. open Shift Gnd U El
  15. import Inst
  16. open Inst Gnd U El
  17. data _-[_]_ : Cxt -> Kind -> Cxt -> Set where
  18. ES : {D : Cxt}{C : Kind} -> EC -[ C ] D
  19. _[_-_:=_] : {G D : Cxt}{C : Kind} -> (G -[ C ] D) ->
  20. (x : Nom){Gx : [| G Hasn't x |]}(S : Kind) ->
  21. D [! C !]- S ->
  22. (G [ x - S ]){Gx} -[ C ] D
  23. fetch : {G D : Cxt}{C S : Kind} -> (G -[ C ] D) ->
  24. Nom :- GooN G S -> D [! C !]- S
  25. fetch ES [ x / () ]
  26. fetch (g [ x - S := s ]) [ y / p ] with nomEq x y
  27. fetch (g [ x - S := s ]) [ .x / refl ] | yes refl = s
  28. fetch (g [ x - S := s ]) [ y / p ] | no n = fetch g [ y / p ]
  29. closed : {G : Cxt}{L : Loc}{T : Kind} ->
  30. G [ EL / Head ]- T -> G [ L / Head ]- T
  31. closed (` x -! xg) = ` x -! xg
  32. closed (# () -! _)
  33. mutual
  34. wsubst : {C : Kind}{G D : Cxt} -> (G -[ C ] D) ->
  35. {L : Loc}{T : Kind}(t : L [ Term C ]- T) -> [| Good G t |] ->
  36. D [ L / Term C ]- T
  37. wsubst g [ s ] sg = G[ wsubsts g s sg ]
  38. wsubst g (fn A f) fg = Gfn A \ a -> wsubst g (f a) (fg a)
  39. wsubst g (\\ b) bg = G\\ (wsubst g b bg)
  40. wsubst g (# v $ s) pg = (# v -! _) G$ wsubsts g s (snd pg)
  41. wsubst g (` x $ s) pg =
  42. go (shift closed (fetch g [ x / fst pg ])) (wsubsts g s (snd pg))
  43. wsubsts : {C : Kind}{G D : Cxt} -> (G -[ C ] D) ->
  44. {L : Loc}{Z : Gnd}{S : Kind}
  45. (s : L [ Args C Z ]- S) -> [| Good G s |] ->
  46. D [ L / Args C Z ]- S
  47. wsubsts g (a ^ s) sg = a G^ wsubsts g s sg
  48. wsubsts g (r & s) pg = wsubst g r (fst pg) G& wsubsts g s (snd pg)
  49. wsubsts g nil _ = Gnil
  50. subst : {C : Kind}{G D : Cxt} -> (G -[ C ] D) ->
  51. {L : Loc}{T : Kind} -> G [ L / Term C ]- T -> D [ L / Term C ]- T
  52. subst g (t -! tg) = wsubst g t tg