Clojure static typing

I know that this may sound like blasphemy to Lisp aficionados (and other lovers of dynamic languages), but how difficult would it be to enhance the Clojure compiler to support static (compile-time) type checking?

Setting aside the arguments for and against static and dynamic typing, is this possible (not "is this advisable")?

I was thinking that adding a new reader macro to force a compile-time type (an enhanced version of the #^ macro) and adding the type information to the symbol table would allow the compiler to flag places where a variables was misused. For example, in the following code, I would expect a compile-time error (#* is the "compile-time" type macro):

(defn get-length [#*String s] (.length s))
(defn test-get-length [] (get-length 2.0))

The #^ macro could even be reused with a global variable ( *compile-time-type-checking* ) to force the compiler the do the checks.

Any thoughts on the feasibility?


It's certainly possible. The compiler already does some static type checking around primitive argument types in the 1.3 development branch.


It certain possible. However I do not think that Clojure will ever get any form of weak static typing - it's benefits are too few.

Rich Hickey has however expressed on several occasions his like for the strong, optional, and expressive typing feature of the Qi language, http://www.lambdassociates.org/qilisp.htm

替代文字


Yes! It looks like there is a project underway, core.typed , to make optional static type checking a reality. See the Github project and its documentation

This work grew out of an undergraduate honours dissertation (PDF) by Ambrose Bonnaire-Sergeant, and is related to the Typed Racket system.

链接地址: http://www.djcxy.com/p/33620.html

上一篇: 函数式编程的工程方法?

下一篇: Clojure静态打字