It’s much better to be able to fix errors up front than to just test a lot and hope for the best.
Turns run-time errors into compile-time errors Given an expressive type system, just looking at a function’s type tells you a lot about what the function might do and how it can be used, even before you have read a single word of written documentation.Īnd it goes the other way: If you are using existing code, such as a library, and you are searching for a specific functionality, you often anticipate the type of the function you need, and you can find it based on that. Because Haskell’s type system is so expressive, this is a non-trivial design step and is an immense help in clarifying one’s thinking about the program. The first step in writing a Haskell program is usually to write down all the types. Helps clarify thinking and express program structure But this isn’t because static type systems per se are annoying it’s because C++ and Java’s type systems are insufficiently expressive! This semester we’ll take a close look at Haskell’s type system, which In fact, in languages like C++ and Java, they are annoying.
Throughout this course, we will focus on three main themes. Programs with type errors will not even compile, much less run.
Parallelism: Evaluating expressions in parallel is easy when they are guaranteed not to affect one another.įewer headaches: Simply put, unrestricted effects and action-at-a-distance makes for programs that are hard to debug, maintain, and reason about.Įvery Haskell expression has a type, and types are all checked at compile-time. But once you’ve made the shift, there are a number of wonderful benefits:Įquational reasoning and refactoring: In Haskell one can always “replace equals by equals”, just like you learned in algebra class. How is it even possible to get anything done without mutation or side effects? Well, it certainly requires a shift in thinking (if you’re used to an imperative or object-oriented paradigm). No mutation! Everything (variables, data structures…) is immutable.Įxpressions never have “side effects” (like updating global variables or printing to the screen).Ĭalling the same function with the same arguments results in the same output every time. Haskell expressions are always referentially transparent, that is: