|
@@ -21126,9 +21126,9 @@ variables.
|
|
|
|
|
|
By including the \code{All} type in the $\Type$ non-terminal of the
|
|
By including the \code{All} type in the $\Type$ non-terminal of the
|
|
grammar we choose to make generics first-class, which has interesting
|
|
grammar we choose to make generics first-class, which has interesting
|
|
-repercussions on the compiler.\footnote{The Python typing library does
|
|
|
|
- not include the \code{All} type, we are taking the liberty to add
|
|
|
|
- the \code{All} type.} Many languages with generics, such as
|
|
|
|
|
|
+repercussions on the compiler.\footnote{The Python \code{typing} library does
|
|
|
|
+not include syntax for the \code{All} type. It is inferred for functions whose
|
|
|
|
+type annotations contain type variables.} Many languages with generics, such as
|
|
C++~\citep{stroustrup88:_param_types} and Standard
|
|
C++~\citep{stroustrup88:_param_types} and Standard
|
|
ML~\citep{Milner:1990fk}, only support second-class generics, so it
|
|
ML~\citep{Milner:1990fk}, only support second-class generics, so it
|
|
may be helpful to see an example of first-class generics in action. In
|
|
may be helpful to see an example of first-class generics in action. In
|
|
@@ -21257,6 +21257,7 @@ example is listed in Figure~\ref{fig:map-type-check}.
|
|
\begin{figure}[tbp]
|
|
\begin{figure}[tbp]
|
|
% poly_test_2.rkt
|
|
% poly_test_2.rkt
|
|
\begin{tcolorbox}[colback=white]
|
|
\begin{tcolorbox}[colback=white]
|
|
|
|
+\if\edition\racketEd
|
|
\begin{lstlisting}
|
|
\begin{lstlisting}
|
|
(poly (a) (define (map [f : (a -> a)] [v : (Vector a a)]) : (Vector a a)
|
|
(poly (a) (define (map [f : (a -> a)] [v : (Vector a a)]) : (Vector a a)
|
|
(vector (f (vector-ref v 0)) (f (vector-ref v 1)))))
|
|
(vector (f (vector-ref v 0)) (f (vector-ref v 1)))))
|
|
@@ -21267,13 +21268,18 @@ example is listed in Figure~\ref{fig:map-type-check}.
|
|
(Integer))
|
|
(Integer))
|
|
inc (vector 0 41)) 1)
|
|
inc (vector 0 41)) 1)
|
|
\end{lstlisting}
|
|
\end{lstlisting}
|
|
|
|
+\fi
|
|
|
|
+\if\edition\pythonEd
|
|
|
|
+UNDER CONSTRUCTION
|
|
|
|
+\fi
|
|
\end{tcolorbox}
|
|
\end{tcolorbox}
|
|
\caption{Output of the type checker on the \code{map} example.}
|
|
\caption{Output of the type checker on the \code{map} example.}
|
|
\label{fig:map-type-check}
|
|
\label{fig:map-type-check}
|
|
\end{figure}
|
|
\end{figure}
|
|
|
|
|
|
\begin{figure}[tbp]
|
|
\begin{figure}[tbp]
|
|
-\begin{tcolorbox}[colback=white]
|
|
|
|
|
|
+ \begin{tcolorbox}[colback=white]
|
|
|
|
+\if\edition\racketEd
|
|
\begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
|
|
\begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
|
|
(define type-check-poly-class
|
|
(define type-check-poly-class
|
|
(class type-check-Llambda-class
|
|
(class type-check-Llambda-class
|
|
@@ -21340,6 +21346,10 @@ example is listed in Figure~\ref{fig:map-type-check}.
|
|
(ProgramDefsExp info ds^^ body^)]))
|
|
(ProgramDefsExp info ds^^ body^)]))
|
|
))
|
|
))
|
|
\end{lstlisting}
|
|
\end{lstlisting}
|
|
|
|
+\fi
|
|
|
|
+\if\edition\pythonEd
|
|
|
|
+UNDER CONSTRUCTION
|
|
|
|
+\fi
|
|
\end{tcolorbox}
|
|
\end{tcolorbox}
|
|
|
|
|
|
\caption{Type checker for the \LangPoly{} language.}
|
|
\caption{Type checker for the \LangPoly{} language.}
|
|
@@ -21348,6 +21358,7 @@ example is listed in Figure~\ref{fig:map-type-check}.
|
|
|
|
|
|
\begin{figure}[tbp]
|
|
\begin{figure}[tbp]
|
|
\begin{tcolorbox}[colback=white]
|
|
\begin{tcolorbox}[colback=white]
|
|
|
|
+\if\edition\racketEd
|
|
\begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
|
|
\begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
|
|
(define/override (type-equal? t1 t2)
|
|
(define/override (type-equal? t1 t2)
|
|
(match* (t1 t2)
|
|
(match* (t1 t2)
|
|
@@ -21409,6 +21420,10 @@ example is listed in Figure~\ref{fig:map-type-check}.
|
|
[`(,(Def f params rt info body) . ,ds^)
|
|
[`(,(Def f params rt info body) . ,ds^)
|
|
(cons (Def f params rt info body) (combine-decls-defs ds^))]))
|
|
(cons (Def f params rt info body) (combine-decls-defs ds^))]))
|
|
\end{lstlisting}
|
|
\end{lstlisting}
|
|
|
|
+\fi
|
|
|
|
+\if\edition\pythonEd
|
|
|
|
+UNDER CONSTRUCTION
|
|
|
|
+\fi
|
|
\end{tcolorbox}
|
|
\end{tcolorbox}
|
|
|
|
|
|
\caption{Auxiliary functions for type checking \LangPoly{}.}
|
|
\caption{Auxiliary functions for type checking \LangPoly{}.}
|
|
@@ -21418,6 +21433,7 @@ example is listed in Figure~\ref{fig:map-type-check}.
|
|
|
|
|
|
\begin{figure}[tbp]
|
|
\begin{figure}[tbp]
|
|
\begin{tcolorbox}[colback=white]
|
|
\begin{tcolorbox}[colback=white]
|
|
|
|
+\if\edition\racketEd
|
|
\begin{lstlisting}%[basicstyle=\ttfamily\scriptsize]
|
|
\begin{lstlisting}%[basicstyle=\ttfamily\scriptsize]
|
|
(define/public ((check-well-formed env) ty)
|
|
(define/public ((check-well-formed env) ty)
|
|
(match ty
|
|
(match ty
|
|
@@ -21438,6 +21454,10 @@ example is listed in Figure~\ref{fig:map-type-check}.
|
|
((check-well-formed env^) t)]
|
|
((check-well-formed env^) t)]
|
|
[else (error 'type-check "unrecognized type ~a" ty)]))
|
|
[else (error 'type-check "unrecognized type ~a" ty)]))
|
|
\end{lstlisting}
|
|
\end{lstlisting}
|
|
|
|
+\fi
|
|
|
|
+\if\edition\pythonEd
|
|
|
|
+UNDER CONSTRUCTION
|
|
|
|
+\fi
|
|
\end{tcolorbox}
|
|
\end{tcolorbox}
|
|
|
|
|
|
\caption{Well-formed types.}
|
|
\caption{Well-formed types.}
|
|
@@ -21529,6 +21549,7 @@ type parameter \code{a} are replaced by \CANYTY{} and the polymorphic
|
|
|
|
|
|
\begin{figure}[tbp]
|
|
\begin{figure}[tbp]
|
|
\begin{tcolorbox}[colback=white]
|
|
\begin{tcolorbox}[colback=white]
|
|
|
|
+\if\edition\racketEd
|
|
\begin{lstlisting}
|
|
\begin{lstlisting}
|
|
(define (map [f : (Any -> Any)] [v : (Vector Any Any)])
|
|
(define (map [f : (Any -> Any)] [v : (Vector Any Any)])
|
|
: (Vector Any Any)
|
|
: (Vector Any Any)
|
|
@@ -21542,6 +21563,10 @@ type parameter \code{a} are replaced by \CANYTY{} and the polymorphic
|
|
-> (Vector Integer Integer)))
|
|
-> (Vector Integer Integer)))
|
|
inc (vector 0 41)) 1)
|
|
inc (vector 0 41)) 1)
|
|
\end{lstlisting}
|
|
\end{lstlisting}
|
|
|
|
+\fi
|
|
|
|
+\if\edition\pythonEd
|
|
|
|
+UNDER CONSTRUCTION
|
|
|
|
+\fi
|
|
\end{tcolorbox}
|
|
\end{tcolorbox}
|
|
|
|
|
|
\caption{The polymorphic \code{map} example after type erasure.}
|
|
\caption{The polymorphic \code{map} example after type erasure.}
|
|
@@ -21626,6 +21651,7 @@ annotations and the body.
|
|
|
|
|
|
\begin{figure}[p]
|
|
\begin{figure}[p]
|
|
\begin{tcolorbox}[colback=white]
|
|
\begin{tcolorbox}[colback=white]
|
|
|
|
+\if\edition\racketEd
|
|
\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.85]
|
|
\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.85]
|
|
\node (Lpoly) at (12,4) {\large \LangPoly{}};
|
|
\node (Lpoly) at (12,4) {\large \LangPoly{}};
|
|
\node (Lpolyp) at (9,4) {\large \LangInst{}};
|
|
\node (Lpolyp) at (9,4) {\large \LangInst{}};
|
|
@@ -21694,6 +21720,10 @@ annotations and the body.
|
|
{\ttfamily\footnotesize patch\_instr.} (x86-4);
|
|
{\ttfamily\footnotesize patch\_instr.} (x86-4);
|
|
\path[->,bend left=15] (x86-4) edge [right] node {\ttfamily\footnotesize prelude\_and\_conc.} (x86-5);
|
|
\path[->,bend left=15] (x86-4) edge [right] node {\ttfamily\footnotesize prelude\_and\_conc.} (x86-5);
|
|
\end{tikzpicture}
|
|
\end{tikzpicture}
|
|
|
|
+\fi
|
|
|
|
+\if\edition\pythonEd
|
|
|
|
+UNDER CONSTRUCTION
|
|
|
|
+\fi
|
|
\end{tcolorbox}
|
|
\end{tcolorbox}
|
|
|
|
|
|
\caption{Diagram of the passes for \LangPoly{} (parametric polymorphism).}
|
|
\caption{Diagram of the passes for \LangPoly{} (parametric polymorphism).}
|