Inst.agda 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. module Inst (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. mutual
  16. winst : {G : Cxt}{C : Kind}{L : Loc}{I : Kind}
  17. (x : L ! I) -> G [ L bar x / Term C ]- I ->
  18. {T : Kind}(t : L [ Term C ]- T) -> [| Good G t |] ->
  19. G [ L bar x / Term C ]- T
  20. winst x i [ s ] sg = G[ winsts x i s sg ]
  21. winst x i (fn A f) fg = Gfn A \ a -> winst x i (f a) (fg a)
  22. winst x i (\\ b) bg = G\\ (winst (pop x) (shift popH i) b bg)
  23. winst x i (h $ s) pg = wing x i h (fst pg) (winsts x i s (snd pg))
  24. winsts : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd}{I : Kind}
  25. (x : L ! I) -> G [ L bar x / Term C ]- I ->
  26. {T : Kind}(s : L [ Args C Z ]- T) -> [| Good G s |] ->
  27. G [ L bar x / Args C Z ]- T
  28. winsts x i (a ^ s) sg = a G^ winsts x i s sg
  29. winsts x i (r & s) pg = winst x i r (fst pg) G& winsts x i s (snd pg)
  30. winsts x i nil _ = Gnil
  31. wing : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd}{I : Kind}
  32. (x : L ! I) -> G [ L bar x / Term C ]- I ->
  33. {T : Kind}(h : L [ Head ]- T) -> [| Good G h |] ->
  34. G [ L bar x / Args C Z ]- T ->
  35. G [ L bar x / Term C ]- Ty Z
  36. wing x i (` k) kg s = (` k -! kg) G$ s
  37. wing x i (# y) _ s with varQV x y
  38. wing x i (# .x) _ s | vSame = go i s
  39. wing x i (# .(x thin y)) _ s | vDiff y = (# y -! _) G$ s
  40. go : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd}{I : Kind} ->
  41. G [ L / Term C ]- I -> G [ L / Args C Z ]- I ->
  42. G [ L / Term C ]- Ty Z
  43. go (fn A f -! fg) ((a ^ s) -! sg) = go (f a -! fg a) (s -! sg)
  44. go (\\ b -! bg) ((r & s) -! pg) =
  45. go (winst top (r -! fst pg) b bg) (s -! snd pg)
  46. go t (nil -! _) = t
  47. inst : {G : Cxt}{C : Kind}{L : Loc}{I : Kind}
  48. (x : L ! I) -> G [ L bar x / Term C ]- I ->
  49. {T : Kind} -> G [ L / Term C ]- T -> G [ L bar x / Term C ]- T
  50. inst x i (t -! tg) = winst x i t tg
  51. _$$_ : {G : Cxt}{C S T : Kind}{L : Loc} ->
  52. G [! C !]- (S |> T) -> G [! C !]- S -> G [! C !]- T
  53. (\\ b -! bg) $$ sg = inst top sg (b -! bg)