Type inference, static checkers and IDEs

April 29, 2009

In Haskell every function has a type. If you don’t tell it the type of your function, it’ll infer it for you.

Prelude> let plus a b = a + b
Prelude> :t plus
plus :: (Num a) => a -> a -> a

Some Haskell programmers write out the type of every function they write. It’s a tradeoff. The function becomes a little more resistant to change, because you might need to change the type signature if you change the function. In return, you get compiler-checked documentation for your function, right there in the code.

Of course, data in other languages have types too, whether or not the language enforces them. It would be perfectly possible for a JavaScript static checker to figure out there’s a problem if you subtract a string from an integer.

var i = 7, s = "asdf";
print(i - s);

The types of i and s might change later, but at the print statement, they’re a number and a string.

I’ve discussed this with Patrick Dubroy and Zak Kincaid, and we agree: A better way would be to have your IDE perform the analysis and make the information available live. I’m not sure how the information would be ideally presented (maybe as a tooltip, or as a specially marked insertion in the editing window) but it would be great to explore.


3 Responses to “Type inference, static checkers and IDEs”

  1. Blake Winton Says:

    I was just listening to the StackOverflow podcast #50 (http://blog.stackoverflow.com/2009/04/podcast-50/), and they mentioned a JavaScript compiler at Google that they use to do both minimization and static checking, so yeah, it’s not only perfectly possible, it already exists. 🙂


  2. […] Zak informs me that the Scala Eclipse plugin has inferred type hovers. Go Scala. May you change the world of IDEs forever in ways I’ve predicted. […]

Comments are closed.

%d bloggers like this: