Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure static typing

Tags:

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?

like image 761
Ralph Avatar asked Nov 15 '10 13:11

Ralph


People also ask

Is Clojure statically typed?

C is statically and weakly typed. Clojure is dynamically and strongly typed. PHP is dynamically and weakly typed. Haskell is statically and strongly typed.

Is Clojure static or dynamic?

First and foremost, Clojure is dynamic. That means that a Clojure program is not just something you compile and run, but something with which you can interact.

Is Lisp statically typed?

Static type checking in the programmable programming language (Lisp) There is a misconception that Lisp is a dynamically typed language and doesn't offer compile-time type checking. Lisp being the programmable programming language that is of course not true.


1 Answers

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

alt text

like image 165
dnolen Avatar answered Sep 28 '22 16:09

dnolen