Term.agda 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. module Term (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 module KindGUEl = Kind Gnd U El
  7. import Loc
  8. open module LocK = Loc Kind
  9. import Cxt
  10. open module CxtK = Cxt Kind
  11. data Jud : Set where
  12. Term : Kind -> Jud
  13. Args : Kind -> Gnd -> Jud
  14. Head : Jud
  15. data _[_]-_ : Loc -> Jud -> Kind -> Set where
  16. [_] : {C : Kind}{L : Loc}{Z : Gnd} ->
  17. L [ Args C Z ]- C -> L [ Term C ]- Ty Z
  18. fn : {C : Kind}{L : Loc}(A : U){K : El A -> Kind} ->
  19. ((x : El A) -> L [ Term C ]- K x) -> L [ Term C ]- Pi A K
  20. \\ : {C : Kind}{L : Loc}{S T : Kind} ->
  21. (L * S) [ Term C ]- T -> L [ Term C ]- (S |> T)
  22. _^_ : {C : Kind}{L : Loc}{Z : Gnd}{A : U}{K : El A -> Kind} ->
  23. (x : El A) -> L [ Args C Z ]- K x -> L [ Args C Z ]- Pi A K
  24. _&_ : {C : Kind}{L : Loc}{S T : Kind}{Z : Gnd} ->
  25. L [ Term C ]- S -> L [ Args C Z ]- T -> L [ Args C Z ]- (S |> T)
  26. nil : {C : Kind}{L : Loc}{Z : Gnd} -> L [ Args C Z ]- Ty Z
  27. _$_ : {C : Kind}{L : Loc}{T : Kind}{Z : Gnd} ->
  28. L [ Head ]- T -> L [ Args C Z ]- T -> L [ Term C ]- Ty Z
  29. ` : Nom -> {S : Kind}{L : Loc} -> L [ Head ]- S
  30. # : {L : Loc}{S : Kind} -> L ! S -> L [ Head ]- S
  31. infixr 90 _^_ _&_
  32. infix 40 _[_]-_
  33. Good : Cxt -> {L : Loc}{j : Jud}{T : Kind} -> L [ j ]- T -> Pr
  34. Good G [ c ] = Good G c
  35. Good G (fn A f) = all (El A) \a -> Good G (f a)
  36. Good G (\\ b) = Good G b
  37. Good G (a ^ ss) = Good G ss
  38. Good G (s & ss) = Good G s /\ Good G ss
  39. Good G nil = tt
  40. Good G (x $ ss) = Good G x /\ Good G ss
  41. Good G (` x {S}) = GooN G S x
  42. Good G (# v) = tt
  43. data _[_/_]-_ (G : Cxt)(L : Loc)(j : Jud)(T : Kind) : Set where
  44. _-!_ : (t : L [ j ]- T) -> [| Good G t |] -> G [ L / j ]- T
  45. gtm : {G : Cxt}{L : Loc}{j : Jud}{T : Kind} -> G [ L / j ]- T -> L [ j ]- T
  46. gtm (t -! _) = t
  47. good : {G : Cxt}{L : Loc}{j : Jud}{T : Kind}
  48. (t : G [ L / j ]- T) -> [| Good G (gtm t) |]
  49. good (t -! g) = g
  50. _[!_!]-_ : Cxt -> Kind -> Kind -> Set
  51. G [! C !]- T = G [ EL / Term C ]- T
  52. G[_] : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd} ->
  53. G [ L / Args C Z ]- C ->
  54. ----------------------------
  55. G [ L / Term C ]- Ty Z
  56. G[ c -! cg ] = [ c ] -! cg
  57. Gfn : {G : Cxt}{C : Kind}{L : Loc}(A : U){K : El A -> Kind} ->
  58. ((x : El A) -> G [ L / Term C ]- K x) ->
  59. -------------------------------------------
  60. G [ L / Term C ]- Pi A K
  61. Gfn A f = fn A (gtm o f) -! (good o f)
  62. G\\ : {G : Cxt}{C : Kind}{L : Loc}{S T : Kind} ->
  63. G [ L * S / Term C ]- T ->
  64. ------------------------------
  65. G [ L / Term C ]- (S |> T)
  66. G\\ (b -! bg) = \\ b -! bg
  67. _G^_ : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd}{A : U}{K : El A -> Kind} ->
  68. (x : El A) ->
  69. G [ L / Args C Z ]- K x ->
  70. ------------------------------
  71. G [ L / Args C Z ]- Pi A K
  72. a G^ (s -! sg) = (a ^ s) -! sg
  73. _G&_ : {G : Cxt}{C : Kind}{L : Loc}{S T : Kind}{Z : Gnd} ->
  74. G [ L / Term C ]- S ->
  75. G [ L / Args C Z ]- T ->
  76. ----------------------------------
  77. G [ L / Args C Z ]- (S |> T)
  78. (r -! rg) G& (s -! sg) = (r & s) -! (rg , sg)
  79. Gnil : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd} ->
  80. -----------------------------
  81. G [ L / Args C Z ]- Ty Z
  82. Gnil = nil -! _
  83. _G$_ : {G : Cxt}{C : Kind}{L : Loc}{T : Kind}{Z : Gnd} ->
  84. G [ L / Head ]- T ->
  85. G [ L / Args C Z ]- T ->
  86. -----------------------------
  87. G [ L / Term C ]- Ty Z
  88. (h -! hg) G$ (s -! sg) = (h $ s) -! (hg , sg)
  89. G` : {G : Cxt}{S : Kind}{L : Loc} -> Nom :- GooN G S ->
  90. ------------------------------------------------------
  91. G [ L / Head ]- S
  92. G` [ x / xg ] = ` x -! xg
  93. G# : {G : Cxt}{L : Loc}{S : Kind} -> L ! S ->
  94. --------------------------
  95. G [ L / Head ]- S
  96. G# v = # v -! _
  97. infixr 90 _G^_ _G&_