5,272 research outputs found
Trust, but Verify: Two-Phase Typing for Dynamic Languages
A key challenge when statically typing so-called dynamic languages is the
ubiquity of value-based overloading, where a given function can dynamically
reflect upon and behave according to the types of its arguments. Thus, to
establish basic types, the analysis must reason precisely about values, but in
the presence of higher-order functions and polymorphism, this reasoning itself
can require basic types. In this paper we address this chicken-and-egg problem
by introducing the framework of two-phased typing. The first "trust" phase
performs classical, i.e. flow-, path- and value-insensitive type checking to
assign basic types to various program expressions. When the check inevitably
runs into "errors" due to value-insensitivity, it wraps problematic expressions
with DEAD-casts, which explicate the trust obligations that must be discharged
by the second phase. The second phase uses refinement typing, a flow- and
path-sensitive analysis, that decorates the first phase's types with logical
predicates to track value relationships and thereby verify the casts and
establish other correctness properties for dynamically typed languages
TreatJS: Higher-Order Contracts for JavaScript
TreatJS is a language embedded, higher-order contract system for JavaScript
which enforces contracts by run-time monitoring. Beyond providing the standard
abstractions for building higher-order contracts (base, function, and object
contracts), TreatJS's novel contributions are its guarantee of non-interfering
contract execution, its systematic approach to blame assignment, its support
for contracts in the style of union and intersection types, and its notion of a
parameterized contract scope, which is the building block for composable
run-time generated contracts that generalize dependent function contracts.
TreatJS is implemented as a library so that all aspects of a contract can be
specified using the full JavaScript language. The library relies on JavaScript
proxies to guarantee full interposition for contracts. It further exploits
JavaScript's reflective features to run contracts in a sandbox environment,
which guarantees that the execution of contract code does not modify the
application state. No source code transformation or change in the JavaScript
run-time system is required.
The impact of contracts on execution speed is evaluated using the Google
Octane benchmark.Comment: Technical Repor
Covariance and Controvariance: a fresh look at an old issue (a primer in advanced type systems for learning functional programmers)
Twenty years ago, in an article titled "Covariance and contravariance:
conflict without a cause", I argued that covariant and contravariant
specialization of method parameters in object-oriented programming had
different purposes and deduced that, not only they could, but actually they
should both coexist in the same language.
In this work I reexamine the result of that article in the light of recent
advances in (sub-)typing theory and programming languages, taking a fresh look
at this old issue.
Actually, the revamping of this problem is just an excuse for writing an
essay that aims at explaining sophisticated type-theoretic concepts, in simple
terms and by examples, to undergraduate computer science students and/or
willing functional programmers.
Finally, I took advantage of this opportunity to describe some undocumented
advanced techniques of type-systems implementation that are known only to few
insiders that dug in the code of some compilers: therefore, even expert
language designers and implementers may find this work worth of reading
- …