Pregunta

Sé que esto puede sonar como una blasfemia para los aficionados a Lisp (y otros amantes de los lenguajes dinámicos), pero lo difícil que iba a ser para mejorar el compilador Clojure de apoyo estática (tiempo de compilación) Tipo de cheques?

Dejando a un lado los argumentos a favor y en contra estática y tipado dinámico, es esto posible (no "es lo aconsejen")?

Yo pensaba que la adición de una nueva macro lector para obligar a un tipo en tiempo de compilación (una versión mejorada del # ^ macro) y añadiendo la información del tipo de la tabla de símbolos que permitiría que el compilador lugares bandera donde se abuse de una las variables . Por ejemplo, en el código siguiente, yo esperaría un error en tiempo de compilación (# * es el "tiempo de compilación" tipo de macro):

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

El # ^ macro incluso podría volver a usar con una variable global (*compile-time-type-checking*) para forzar al compilador la hacen los controles.

¿Alguna idea sobre la viabilidad?

¿Fue útil?

Solución

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

Otros consejos

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

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.

Since one form is read AND evaluated at a time you cannot have forward references making this somewhat limited.

Old question but two important points: I don't think Clojure supports reader macros, only ordinary lisp macros. And now we have core.typed option for typing in Clojure.

declare can have type hints, so it is possible to declare a var that "is" the type which has not been defined yet but contains data about the structure, but this would be really clunky and you would have to do it before any code path that could be executed before the type is defined. Basically, you would want to define all of your user defined types up front and then use them like normal. I think that makes library writing somewhat hackish.

I didn't mean to suggest earlier that this isn't possible, just that for user defined types it is a lot more complicated than for pre-defined types. The benefit of doing this vs. the cost is something that should be seriously considered. But I encourage anyone who is interested to try it out and see if they can make it work!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top