Re:First look at Clojure.core.typed
by swannodette on Thursday August 29, 2013 @01:11PM
(#6297033)
Clojure's type hints are only about Java interop and performance, and pretending otherwise is not a good idea. They aren't nearly rich enough to do the things that Typed Clojure does - think about less trivial examples like type checking heterogenous maps.
Ah, I didn't realize that core.typed could deal with rich data structures like that. That's actually pretty amazing.
Re:First look at Clojure.core.typed
by JackMorgan on Thursday August 29, 2013 @12:49PM
(#6296883)
I wanted something like this, so I made this library that checks annotations at run time rather than compile time.
https://github.com/steveshogren/deft
Right now it only checks maps for a set of keys, the idea longer term is to add in other types of "type" checking.
I haven't yet tied into the built-in annotations, just because those didn't appear to check anything but valid Java types. If it is possible, I would be really interested in seeing how.
(ann my-inc [Number -> Number])
(defn my-inc [n] (let [internal-number (Integer/parseInt "1")] (+ n internal-number)))
one could write this:
(defn ^Number my-inc [^Number n] (let [internal-number (Integer/parseInt "1")] (+ n internal-number)))
...and then run a type checker that reads and analyzes the hints?
Of course, the core.typed annotations could preserve whatever information they need in the compiled output, whereas the type hints aren't preserved past the compile phase (as far as I can tell.) Is that the limitation that requires defining type information in separate annotations?