3 ms·
Sure, type systems are very practical. I wouldn't want to program without a good one any more. But that's not really why I find them interesting. Mostly, I jus
by tikhonj 14y ago
Sure, type systems are very practical. I wouldn't want to program without a good one any more.
But that's not really why I find them interesting. Mostly, I just find most type theory simple and beautiful. It's fun and gives me a new perspective on how to think about computation (as transformations between types).
Also, while a type system restricts the set of possible programs, it can actually make a language more expressive. Haskell's typeclasses make a whole bunch of things much nicer: custom numeric types, overloaded string literals, monads, QuickCheck... All this is far uglier in a language without typeclasses.
Coincidentally, I'm very excited that Rust is promising to bring much of the typeclassy goodness to low-level programming. It really does make life much nicer, and promises to bring some progress to the otherwise seemingly stagnant field of systems languages. I think that's the sort of innovation we really need rather than Go, but I'm obviously very biased :).
- ufo 14y agodon't common lisp multimethods do kind of the same thing as typeclasses but on a dynamic language?
- tikhonj 14y agoThey're missing one very important part: dispatching on the return type. All my examples require that. That is, in Haskell, numeric literals are polymorphic on the type they are supposed to be: the type system can infer whether you need an Int, an Integer, a Double, a Word or even a Word18--which my last project did--just from using a literal number. In every other language I know, you would have to specify which one you wanted somehow, either by using a current syntax (like 0L or 0.1) or calling a function on the number. In Haskell, the type system can figure it out for you.
- FreeFull 14y agoThe way this happens underneath is that every type that has a Num instance has a fromInteger function. If a literal like 3435 is encountered, the fromInteger function gets called on it to convert it to the appropriate type.