Won't gradual typing require integration with the Clojure compiler?

25 views
Skip to first unread message

Chris Cornelison

unread,
Oct 6, 2015, 5:16:46 PM10/6/15
to core.typed
In Ambrose's Strange Loop talk... 


The language mediator and the need for runtime contracts (perhaps via proxying) are discussed. The talk continues with a discussion of how Typed Racket achieved this because they had control over the VM, and that the Clojure compiler and the JVM are essentially locked boxes.

This left me somewhat confused.  It would seem that there would "have to be" integration with the Clojure compiler to make gradual typing happen (i.e. the compiler would have to generate and emit runtime contracts).

Is this not the case, or am I missing something?

Thanks,
Chris

Ambrose Bonnaire-Sergeant

unread,
Oct 6, 2015, 5:30:59 PM10/6/15
to core.typed
Hi Chris,

Good question.

There indeed needs to be some sort of interception of compilation, the typed REPL
and require/load monkey patching alluded to in the talk being examples of that.

Here's what happens in the typed REPL.

1. Pipe unevaluated form through tools.analyzer to get an AST
2. Run AST through type checker, which outputs another possibly-different AST
3. Convert the new AST back to a Clojure form and evaluate with clojure.core/eval.

The interception happens in step 2. One nice property is that the runtime semantics
don't depend on the transformations made by the type checker. In other words, modulo
contract errors and a few other gradual-typing related subtleties, a typed form can also
be directly compiled with any Clojure compiler and still get the same results.

Thanks,
Ambrose
Reply all
Reply to author
Forward
0 new messages