comparison doc/manual.tex @ 535:b742bf4e377b

Declaration typing
author Adam Chlipala <adamc@hcoop.net>
date Sat, 29 Nov 2008 11:33:51 -0500
parents 65c253a9ca92
children e32d0f6a1e15
comparison
equal deleted inserted replaced
534:65c253a9ca92 535:b742bf4e377b
179 &&& \mt{open} \; M & \textrm{module inclusion} \\ 179 &&& \mt{open} \; M & \textrm{module inclusion} \\
180 &&& \mt{constraint} \; c \sim c & \textrm{record disjointness constraint} \\ 180 &&& \mt{constraint} \; c \sim c & \textrm{record disjointness constraint} \\
181 &&& \mt{open} \; \mt{constraints} \; M & \textrm{inclusion of just the constraints from a module} \\ 181 &&& \mt{open} \; \mt{constraints} \; M & \textrm{inclusion of just the constraints from a module} \\
182 &&& \mt{table} \; x : c & \textrm{SQL table} \\ 182 &&& \mt{table} \; x : c & \textrm{SQL table} \\
183 &&& \mt{sequence} \; x & \textrm{SQL sequence} \\ 183 &&& \mt{sequence} \; x & \textrm{SQL sequence} \\
184 &&& \mt{cookie} \; x : \tau & \textrm{HTTP cookie} \\
184 &&& \mt{class} \; x = c & \textrm{concrete type class} \\ 185 &&& \mt{class} \; x = c & \textrm{concrete type class} \\
185 &&& \mt{cookie} \; x : \tau & \textrm{HTTP cookie} \\
186 \\ 186 \\
187 \textrm{Modules} & M &::=& \mt{struct} \; d^* \; \mt{end} & \textrm{constant} \\ 187 \textrm{Modules} & M &::=& \mt{struct} \; d^* \; \mt{end} & \textrm{constant} \\
188 &&& X & \textrm{variable} \\ 188 &&& X & \textrm{variable} \\
189 &&& M.X & \textrm{projection} \\ 189 &&& M.X & \textrm{projection} \\
190 &&& M(M) & \textrm{functor application} \\ 190 &&& M(M) & \textrm{functor application} \\
243 \item $\Gamma \vdash c \hookrightarrow C$ proves that record constructor $c$ decomposes into set $C$ of field names and record constructors. 243 \item $\Gamma \vdash c \hookrightarrow C$ proves that record constructor $c$ decomposes into set $C$ of field names and record constructors.
244 \item $\Gamma \vdash c \equiv c$ proves the computational equivalence of two constructors. This is often called a \emph{definitional equality} in the world of type theory. 244 \item $\Gamma \vdash c \equiv c$ proves the computational equivalence of two constructors. This is often called a \emph{definitional equality} in the world of type theory.
245 \item $\Gamma \vdash e : \tau$ is a standard typing judgment. 245 \item $\Gamma \vdash e : \tau$ is a standard typing judgment.
246 \item $\Gamma \vdash p \leadsto \Gamma; \tau$ combines typing of patterns with calculation of which new variables they bind. 246 \item $\Gamma \vdash p \leadsto \Gamma; \tau$ combines typing of patterns with calculation of which new variables they bind.
247 \item $\Gamma \vdash d \leadsto \Gamma$ expresses how a declaration modifies a context. We overload this judgment to apply to sequences of declarations. 247 \item $\Gamma \vdash d \leadsto \Gamma$ expresses how a declaration modifies a context. We overload this judgment to apply to sequences of declarations.
248 \item $\Gamma \vdash S$ is the signature validity judgment.
249 \item $\Gamma \vdash S \leq S$ is the signature compatibility judgment.
248 \item $\Gamma \vdash M : S$ is the module signature checking judgment. 250 \item $\Gamma \vdash M : S$ is the module signature checking judgment.
249 \item $\mt{proj}(M, S, V)$ is a partial function for projecting a signature item from a signature $S$, given the module $M$ that we project from. $V$ may be $\mt{con} \; x$, $\mt{val} \; x$, $\mt{signature} \; X$, or $\mt{structure} \; X$. The parameter $M$ is needed because the projected signature item may refer to other items of $S$. 251 \item $\mt{proj}(M, S, V)$ is a partial function for projecting a signature item from a signature $S$, given the module $M$ that we project from. $V$ may be $\mt{con} \; x$, $\mt{datatype} \; x$, $\mt{val} \; x$, $\mt{signature} \; X$, or $\mt{structure} \; X$. The parameter $M$ is needed because the projected signature item may refer to other items of $S$.
250 \end{itemize} 252 \end{itemize}
251 253
252 \subsection{Kinding} 254 \subsection{Kinding}
253 255
254 $$\infer{\Gamma \vdash (c) :: \kappa :: \kappa}{ 256 $$\infer{\Gamma \vdash (c) :: \kappa :: \kappa}{
519 \quad \infer{\Gamma \vdash \{\overline{x = p}, \ldots\} \leadsto \Gamma_n; \$([\overline{x = \tau}] \rc c)}{ 521 \quad \infer{\Gamma \vdash \{\overline{x = p}, \ldots\} \leadsto \Gamma_n; \$([\overline{x = \tau}] \rc c)}{
520 \Gamma_0 = \Gamma 522 \Gamma_0 = \Gamma
521 & \forall i: \Gamma_i \vdash p_i \leadsto \Gamma_{i+1}; \tau_i 523 & \forall i: \Gamma_i \vdash p_i \leadsto \Gamma_{i+1}; \tau_i
522 }$$ 524 }$$
523 525
526 \subsection{Declaration Typing}
527
528 We use an auxiliary judgment $\overline{y}; x; \Gamma \vdash \overline{dc} \leadsto \Gamma'$, expressing the enrichment of $\Gamma$ with the types of the datatype constructors $\overline{dc}$, when they are known to belong to datatype $x$ with type parameters $\overline{y}$.
529
530 This is the first judgment where we deal with type classes, for the $\mt{class}$ declaration form. We will omit their special handling in this formal specification. In the compiler, a set of available type classes and their instances is maintained, and these instances are used to fill in expression wildcards.
531
532 We presuppose the existence of a function $\mathcal O$, where $\mathcal(M, S)$ implements the $\mt{open}$ declaration by producing a context with the appropriate entry for each available component of module $M$ with signature $S$. Where possible, $\mathcal O$ uses ``transparent'' entries (e.g., an abstract type $M.x$ is mapped to $x :: \mt{Type} = M.x$), so that the relationship with $M$ is maintained. A related function $\mathcal O_c$ builds a context containing the disjointness constraints found in $S$.
533
534 $$\infer{\Gamma \vdash \cdot \leadsto \Gamma}{}
535 \quad \infer{\Gamma \vdash d, \overline{d} \leadsto \Gamma''}{
536 \Gamma \vdash d \leadsto \Gamma'
537 & \Gamma' \vdash \overline{d} \leadsto \Gamma''
538 }$$
539
540 $$\infer{\Gamma \vdash \mt{con} \; x :: \kappa = c \leadsto \Gamma, x :: \kappa = c}{
541 \Gamma \vdash c :: \kappa
542 }
543 \quad \infer{\Gamma \vdash \mt{datatype} \; x \; \overline{y} = \overline{dc} \leadsto \Gamma'}{
544 \overline{y}; x; \Gamma, x :: \mt{Type}^{\mt{len}(\overline y)} \to \mt{Type} \vdash \overline{dc} \leadsto \Gamma'
545 }$$
546
547 $$\infer{\Gamma \vdash \mt{datatype} \; x = \mt{datatype} \; M.z \leadsto \Gamma'}{
548 \Gamma \vdash M : S
549 & \mt{proj}(M, S, \mt{datatype} \; z) = (\overline{y}, \overline{dc})
550 & \overline{y}; x; \Gamma, x :: \mt{Type}^{\mt{len}(\overline y)} \to \mt{Type} = M.z \vdash \overline{dc} \leadsto \Gamma'
551 }$$
552
553 $$\infer{\Gamma \vdash \mt{val} \; x : \tau = e \leadsto \Gamma, x : \tau}{
554 \Gamma \vdash e : \tau
555 }$$
556
557 $$\infer{\Gamma \vdash \mt{val} \; \mt{rec} \; \overline{x : \tau = e} \leadsto \Gamma, \overline{x : \tau}}{
558 \forall i: \Gamma, \overline{x : \tau} \vdash e_i : \tau_i
559 & \textrm{$e_i$ starts with an expression $\lambda$, optionally preceded by constructor and disjointness $\lambda$s}
560 }$$
561
562 $$\infer{\Gamma \vdash \mt{structure} \; X : S = M \leadsto \Gamma, X : S}{
563 \Gamma \vdash M : S
564 }
565 \quad \infer{\Gamma \vdash \mt{siganture} \; X = S \leadsto \Gamma, X = S}{
566 \Gamma \vdash S
567 }$$
568
569 $$\infer{\Gamma \vdash \mt{open} \; M \leadsto \Gamma, \mathcal O(M, S)}{
570 \Gamma \vdash M : S
571 }$$
572
573 $$\infer{\Gamma \vdash \mt{constraint} \; c_1 \sim c_2 \leadsto \Gamma}{
574 \Gamma \vdash c_1 :: \{\kappa\}
575 & \Gamma \vdash c_2 :: \{\kappa\}
576 & \Gamma \vdash c_1 \sim c_2
577 }
578 \quad \infer{\Gamma \vdash \mt{open} \; \mt{constraints} \; M \leadsto \Gamma, \mathcal O_c(M, S)}{
579 \Gamma \vdash M : S
580 }$$
581
582 $$\infer{\Gamma \vdash \mt{table} \; x : c \leadsto \Gamma, x : \mt{Basis}.\mt{sql\_table} \; c}{
583 \Gamma \vdash c :: \{\mt{Type}\}
584 }
585 \quad \infer{\Gamma \vdash \mt{sequence} \; x \leadsto \Gamma, x : \mt{Basis}.\mt{sql\_sequence}}{}$$
586
587 $$\infer{\Gamma \vdash \mt{cookie} \; x : \tau \leadsto \Gamma, x : \mt{Basis}.\mt{http\_cookie} \; \tau}{
588 \Gamma \vdash \tau :: \mt{Type}
589 }$$
590
591 $$\infer{\Gamma \vdash \mt{class} \; x = c \leadsto \Gamma, x :: \mt{Type} \to \mt{Type} = c}{
592 \Gamma \vdash c :: \mt{Type} \to \mt{Type}
593 }$$
594
595 $$\infer{\overline{y}; x; \Gamma \vdash \cdot \leadsto \Gamma}{}
596 \quad \infer{\overline{y}; x; \Gamma \vdash X \mid \overline{dc} \leadsto \Gamma', X : \overline{y ::: \mt{Type}} \to x \; \overline{y}}{
597 \overline{y}; x; \Gamma \vdash \overline{dc} \leadsto \Gamma'
598 }
599 \quad \infer{\overline{y}; x; \Gamma \vdash X \; \mt{of} \; \tau \mid \overline{dc} \leadsto \Gamma', X : \overline{y ::: \mt{Type}} \to \tau \to x \; \overline{y}}{
600 \overline{y}; x; \Gamma \vdash \overline{dc} \leadsto \Gamma'
601 }$$
602
524 \end{document} 603 \end{document}