23.11.2014 Views

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

component types <strong>and</strong> checking that they both have type *.<br />

The rule [C-Let] compiles the term let x = v : S in t by recursively<br />

compiling v, S <strong>and</strong> t in appropriate environments.<br />

The rules for function application are more interesting.<br />

The rule [C-App1] compiles an application t 1 t 2 by compiling<br />

the function t 1 to some term t ′ 1 <strong>of</strong> some type U. The type<br />

U may be a function type embedded inside refinements. In<br />

order to extract the actual type <strong>of</strong> the parameter to the<br />

function, we use unrefine to remove any outer refinements<br />

<strong>of</strong> U before checking the type <strong>of</strong> the argument t 2 against the<br />

expected type. Formally, unrefine is defined as follows:<br />

unrefine : Term → Term<br />

unrefine(x:S → T ) = x:S → T<br />

unrefine(Refine T f) = unrefine(T )<br />

unrefine(S) = unrefine(S ′ ) if S −→ S ′<br />

The last clause permits S to be simplified via evaluation<br />

while removing outer refinements. Given the expressiveness<br />

<strong>of</strong> the type system, this evaluation may not converge within<br />

a given time bound. Hence, to ensure that our compiler<br />

accepts all (arbitrarily complicated) well-typed programs,<br />

the rule [C-App2] provides a backup compilation strategy for<br />

applications that requires less static analysis, but performs<br />

more dynamic checking. This rule checks that the function<br />

expression has the most general function type Dynamic →<br />

Dynamic, <strong>and</strong> correspondingly coerces t 2 to type Dynamic,<br />

resulting in an application with type Dynamic.<br />

The rules defining the compilation <strong>and</strong> checking judgment<br />

E ⊢ s ↩→ t ↓ T<br />

illustrate the key ideas <strong>of</strong> hybrid type checking. The rules<br />

[CC-Ok] <strong>and</strong> [CC-Chk] compile the given term <strong>and</strong> check<br />

that the compiled term has the expected type T via the<br />

algorithmic subtyping judgment<br />

E ⊢ a alg S

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!