core.tex 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. We use Martin-L\"of's logical
  2. framework~\cite{nordstroemPeterssonSmith:handbookLICS} as the underlying logic.
  3. %
  4. The choice of underlying logic is not crucial--the type checking algorithm
  5. presented in this paper can be extended to more feature-rich logics with, for
  6. instance, recursive definitions, pattern matching, and universe hierachies.
  7. \if \NoteOnPatternMatching 1
  8. See Section~\ref{secAddPatternMatching} for a note on how to extend it to
  9. pattern matching.
  10. \fi
  11. \paragraph*{Syntax} The syntax of {\Core} is given by the following grammar.
  12. {\small
  13. \[\begin{array}{lclr}
  14. A, B & ::= & \SET \Or M \Or \PI xAA & \mathit{types} \\
  15. M, N & ::= & x \Or c \Or M\,M \Or \LAM xM & \mathit{terms} \\
  16. \Gamma, \Delta & ::= & () \Or \Gamma,x:A & \mathit{contexts} \\
  17. \Sigma & ::= & () \Or \Sigma,c:A \Or \Sigma,c:A=M & \mathit{signatures} \\
  18. \end{array}\]
  19. }
  20. We assume countable sets of variables and constants and we identify terms up to
  21. $\alpha$-conversion. We adopt the convention that variables in contexts are
  22. distinct. Similarly a constant may not be declared in a signature more than
  23. once.
  24. Repeated application $M \, N_1 \, \dots \, N_k$ is abbreviated $M \, \bar N$.
  25. %
  26. Given a context $\Gamma = x_1 : A_1, \ldots, x_n : A_n$ we sometimes write
  27. $\LAM \Gamma M$ for $\LAM {x_1} \ldots \LAM {x_n} M$ and $M \, \Gamma$ for $M
  28. \, \bar x$.
  29. %
  30. Capture avoiding substitution of $N$ for $x$ in $M$ is written $\Subst M x N$,
  31. or $\SubstD M N$ when $x$ is clear from the context.
  32. %
  33. For dependent function types $\PI xAB$, we write $A \to B$ when $x$ is not free
  34. in $B$.
  35. %
  36. The signature contains axioms and non-recursive definitions.
  37. \paragraph*{Judgements} The type system of {\Core} is presented in six mutually
  38. dependent judgement forms.
  39. {\small
  40. \[\begin{array}{lcl}
  41. \IsSigCS\Sigma && \mbox{$\Sigma$ is a valid signature} \\
  42. \IsCtxCS\Sigma\Gamma && \mbox{$\Gamma$ is a valid context} \\
  43. \IsTypeCS\Sigma\Gamma A && \mbox{$A$ is a valid type in $\Gamma$} \\
  44. \HasTypeCS\Sigma\Gamma MA && \mbox{$M$ has type $A$ in $\Gamma$} \\
  45. \EqualTypeCS\Sigma\Gamma AB && \mbox{$A$ and $B$ are convertible types in $\Gamma$}\\
  46. \EqualCS\Sigma\Gamma MNA &~& \mbox{$M$ and $N$ are convertible terms of type $A$ in $\Gamma$} \\
  47. \end{array}\]
  48. }
  49. The typing rules follows standard presentations of type
  50. theory~\cite{nordstroemPeterssonSmith:handbookLICS}.
  51. \if \DetailedProofs 1
  52. \paragraph*{Properties} When proving the properties of the type checking
  53. algorithm in Section~\ref{secRules} we will need the following properties of
  54. {\Core}.
  55. \begin{lemma}[Uniqueness of types] \label{lemCoreEqType}
  56. \[ \infer{ \EqualTypeC \Gamma A B }
  57. { \HasTypeC \Gamma {c \, \bar M} A
  58. & \HasTypeC \Gamma {c \, \bar M} B
  59. }
  60. \]
  61. \end{lemma}
  62. \begin{lemma} \label{lemCoreAppInv}
  63. \[ \infer{ \HasTypeC \Gamma {\bar M} \Delta }
  64. { \HasTypeC \Gamma c {\Delta \to B}
  65. & \HasTypeC \Gamma {c \, \bar M} {B'}
  66. }
  67. \]
  68. \end{lemma}
  69. \begin{lemma}[Shadowing] \label{lemCoreShadow}
  70. \[ \infer{ \HasTypeC \Gamma {\LAM xM} {\PI xAB}}
  71. { \HasTypeC \Gamma M B
  72. & \HasTypeC \Gamma x A
  73. }
  74. \]
  75. \end{lemma}
  76. \begin{lemma}[Substitution] \label{lemCoreSubstType}
  77. \[ \infer{ \IsTypeC \Gamma {\Subst B x M} }
  78. { \IsTypeC {\Ext \Gamma x:A} B
  79. & \HasTypeC \Gamma M A
  80. }
  81. \]
  82. \end{lemma}
  83. \begin{lemma}[Subject reduction] \label{lemCoreSubjectReduction}
  84. \[ \infer{ \HasTypeC \Gamma {M'} A }
  85. { \HasTypeC \Gamma M A & \whnf M {M'} }
  86. \]
  87. \end{lemma}
  88. \begin{lemma}[Strengthening] \label{lemCoreStrengthen}
  89. \[ \infer{ \HasTypeC \Gamma M B }
  90. { \HasTypeC {\Ext \Gamma {x : A}} M B
  91. & x \notin \FV{M} \cup \FV{B}
  92. }
  93. \]
  94. \end{lemma}
  95. \begin{lemma} \label{lemCoreEqualDummySubst}
  96. If $\EqualTypeCS \Sigma \Gamma {B_1} {\SubstD {B_2} {h \, \bar M}}$ where $h
  97. \, \bar M$ is on weak head normal form and the head $h$ does not occur in
  98. $B_1$, then for any term $M$ of the right type we have $\EqualTypeCS \Sigma
  99. \Gamma {B_1} {\SubstD {B_2} M}$.
  100. \end{lemma}
  101. \fi