|
@@ -20672,7 +20672,7 @@ print(t[1])
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
\begin{figure}[tbp]
|
|
|
\begin{tcolorbox}[colback=white]
|
|
|
-\begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
|
|
|
+\begin{lstlisting}
|
|
|
class TypeCheckLgrad(TypeCheckLlambda):
|
|
|
def type_check_exp(self, e, env) -> Type:
|
|
|
match e:
|
|
@@ -20701,14 +20701,16 @@ class TypeCheckLgrad(TypeCheckLlambda):
|
|
|
func_t = self.type_check_exp(func, env)
|
|
|
args_t = [self.type_check_exp(arg, env) for arg in args]
|
|
|
match func_t:
|
|
|
- case FunctionType(params_t, return_t) if len(params_t) == len(args_t):
|
|
|
+ case FunctionType(params_t, return_t) \
|
|
|
+ if len(params_t) == len(args_t):
|
|
|
for (arg_t, param_t) in zip(args_t, params_t):
|
|
|
self.check_consistent(param_t, arg_t, e)
|
|
|
return return_t
|
|
|
case AnyType():
|
|
|
return AnyType()
|
|
|
case _:
|
|
|
- raise Exception('type_check_exp: in call, unexpected ' + repr(func_t))
|
|
|
+ raise Exception('type_check_exp: in call, unexpected '
|
|
|
+ + repr(func_t))
|
|
|
...
|
|
|
case _:
|
|
|
raise Exception('type_check_exp: unexpected ' + repr(e))
|
|
@@ -21624,7 +21626,7 @@ backward! Functions are contravariant\index{subject}{contravariant}
|
|
|
in the parameters.) Afterward, call the underlying function and then
|
|
|
cast the result from the source return type to the target return type.
|
|
|
Figure~\ref{fig:map-lower-cast} shows the output of the
|
|
|
-\code{lower\_casts} pass on the \code{map} example give in
|
|
|
+\code{lower\_casts} pass on the \code{map} example given in
|
|
|
figure~\ref{fig:gradual-map}. Note that the \code{inc} argument in the
|
|
|
call to \code{map} is wrapped in a \code{lambda}.
|
|
|
|
|
@@ -21938,7 +21940,7 @@ the target type is \code{PVector}. Instead of using
|
|
|
Recall that the $\itm{tagof}$ function determines the bits used to
|
|
|
identify values of different types, and it is used in the \code{reveal\_casts}
|
|
|
pass in the translation of \code{Project}. The \PTUPLETYNAME{} and
|
|
|
-\PARRAYTYNAME{} types can be mapped to $010$ in binary ($2$ is
|
|
|
+\PARRAYTYNAME{} types can be mapped to $010$ in binary ($2$ in
|
|
|
decimal), just like the tuple and array types.
|
|
|
\fi}
|
|
|
%
|
|
@@ -22303,7 +22305,7 @@ needed for the compilation of \LangGrad{}.
|
|
|
|
|
|
This chapter just scratches the surface of gradual typing. The basic
|
|
|
approach described here is missing two key ingredients that one would
|
|
|
-want in a implementation of gradual typing: blame
|
|
|
+want in an implementation of gradual typing: blame
|
|
|
tracking~\citep{Tobin-Hochstadt:2006fk,Wadler:2009qv} and
|
|
|
space-efficient casts~\citep{Herman:2006uq,Herman:2010aa}. The
|
|
|
problem addressed by blame tracking is that when a cast on a
|