Shift.agda 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. module Shift (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. popH : {D : Cxt}{M : Loc}{S T : Kind} ->
  14. D [ M / Head ]- T -> D [ M * S / Head ]- T
  15. popH ( ` x -! xg ) = ` x -! xg
  16. popH ( # v -! _ ) = # (pop v) -! _
  17. weak : {G D : Cxt}{L M : Loc}{S : Kind} ->
  18. ({T : Kind} -> G [ L / Head ]- T -> D [ M / Head ]- T) ->
  19. {T : Kind} -> G [ L * S / Head ]- T -> D [ M * S / Head ]- T
  20. weak rho (` x -! p ) = popH (rho (` x -! p))
  21. weak rho (# top -! _ ) = # top -! _
  22. weak rho (# (pop v) -! _ ) = popH (rho (# v -! _))
  23. shift : {G D : Cxt}{L M : Loc} ->
  24. ({T : Kind} -> G [ L / Head ]- T -> D [ M / Head ]- T) ->
  25. {j : Jud}{T : Kind} -> G [ L / j ]- T -> D [ M / j ]- T
  26. shift {G} {D} rho (t -! tg) = chug rho t tg where
  27. chug : {j : Jud}{L M : Loc} ->
  28. ({T : Kind} -> G [ L / Head ]- T -> D [ M / Head ]- T) ->
  29. {T : Kind}(t : L [ j ]- T) -> [| Good G t |] -> D [ M / j ]- T
  30. chug {Head} rho h hg = rho ( h -! hg )
  31. chug rho [ s ] sg = G[ chug rho s sg ]
  32. chug rho (fn A f) fg = Gfn A (\ a -> chug rho (f a) (fg a))
  33. chug rho (\\ b) bg = G\\ (chug (weak rho) b bg)
  34. chug rho (a ^ s) sg = a G^ chug rho s sg
  35. chug rho (r & s) rsg = chug rho r (fst rsg) G& chug rho s (snd rsg)
  36. chug rho nil _ = Gnil
  37. chug rho (h $ s) hsg = chug rho h (fst hsg) G$ chug rho s (snd hsg)
  38. bind : {G : Cxt}(x : Nom){Gx : [| G Hasn't x |]}{S : Kind}{j : Jud}{T : Kind} ->
  39. (G [ x - S ]) {Gx} [ EL / j ]- T -> G [ EL * S / j ]- T
  40. bind {G} x {Gx}{S} = shift topx where
  41. topx : {T : Kind} -> (G [ x - S ]) {Gx} [ EL / Head ]- T ->
  42. G [ EL * S / Head ]- T
  43. topx (` y -! yg) with nomEq x y
  44. topx (` .x -! refl) | yes refl = # top -! _
  45. topx (` y -! yg) | no _ = ` y -! yg
  46. topx (# () -! _)