Hacker News new | ask | show | jobs
by Tuna-Fish 5287 days ago
Haskell's type system is really not at all comparable to the ones found in c and Java. Not only is the Haskell type system Turing-complete, I'd be willing to argue that it's more expressive (and I mean the type system itself, not the whole language...) than a lot of mainstream languages. Basically, it's a whole different animal from the things most programmers call type systems.

For example, the type system doesn't just handle values, doing actions is also managed by the type system. The type of main is IO (), which roughly means "do something with side-effects". If I write a function that reads in a file and returns a string, it's type is not String, it's IO String, or, "do an action, which causes a String to be returned". I can shuffle this around at will, and use the IO monad to handle running the program in correct order. And IO is just a single way of managing order -- continuation passing is just another monad in the type system, that didn't even need any additional code in the compiler to implement.

But what really makes the difference from Java or C++ imho is the type inference. Basically, if you never write a type declaration, the only time the type system bothers you is when there really is a bug in the code. Psychologically, this is a big deal. In Java, the type system is a chore that makes me type unnecessary things. In Haskell, the type system is a compile-time check that catches a lot of real errors.