This appendix contains typing rules for terms and kinding rules for
predicate constructors. They say what it means for a Ceptre program to be
well formed at the syntactic level. Most of these rules implicitly carry a
signature $\Sigma$, which is not mentioned unless the rule refers to it.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\wf}[1]{#1\ \mathsf{wf}}


\[
\Sigma \vdash \wf{K}
\]

\[
\infer[\mathsf{wf/type}]
{\Sigma \vdash \wf{\type}}{}
\qquad
\infer[\mathsf{wf/pred}]
{\Sigma \vdash \wf{\pred}}{}
\qquad
\infer[\mathsf{wf/bwd}]
{\Sigma \vdash \wf{\bwd}}{}
\]

\[
\infer[\mathsf{wf/arr}]
{\Sigma \vdash \wf{\tau \to P}}
{\Sigma \vdash \tau : \type
  &
 \Sigma \vdash \wf{P}}
\]

(Note: this last rule refers to $P$ rather than $K$ because $\type$ cannot
be indexed by type arguments in Ceptre.)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\[
\Gamma \vdash_{\Sigma} A : K
\]

\[
\infer[\mathsf{ofk/const}]
{\Gamma \vdash_{\Sigma} a : K}
{a{:}K\in \Sigma
&
\Sigma \vdash \wf{K}}
\qquad
\infer[\mathsf{ofk/app}]
{\Gamma \vdash a\ t : K}
{\Gamma \vdash a : \tau \to K
  &
 \Gamma \vdash t : \tau}
\]

\[
\infer[\mathsf{oft/arr}]
{\Gamma \vdash \tau_1 \to \tau_2 : \type}
{\Gamma \vdash \tau_1 : \type
  &
 \Gamma \vdash \tau_2 : \type}
\]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Backward chaining clauses such as
% "plus z (s z) (s z)"
% "Pi n. plus z n z"
% "Pi n,m,p. plus n m p -> plus (s n) m (s p)"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\[
\infer[\mathsf{ofb/pi}]
{
  \Gamma\vdash \Pi{x{:}\tau}.M : \bwd
}
{
  \Gamma, x{:}\tau \vdash M : \bwd
}
\qquad
\infer[\mathsf{ofb/arr}]
{
  \Gamma \vdash p\to B : \bwd
}
{
  \Gamma \vdash p : \bwd
  &
  \Gamma \vdash B : \bwd
}
\]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\[
\Gamma \vdash_{\Sigma} t : \tau 
\]

\[
\infer[\mathsf{oft/const}]
{\Gamma \vdash_{\Sigma} c : \tau}
{c{:}\tau \in \Sigma}
\qquad
\infer[\mathsf{oft/var}]
{\Gamma \vdash x : \tau}
{x{:}\tau \in \Gamma}
\]

\[
\infer[\mathsf{oft/app}]
{\Gamma \vdash c\ t : \tau}
{\Gamma \vdash c : \tau' \to \tau
  &
 \Gamma \vdash t : \tau'}
\]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Proof terms. needed here? Different appendix?
% \[
% \Gamma; \Delta \vdash_{\Sigma} M : S
% \]
