Warning! This blog's new home now is here.
A while ago I've finally started to study Haskell, in particular following the CIS 194: Introduction to Haskell course by Brent Yorgey from the Penn University of Pennsilvania. This is the first resource of the curriculum I plan to follow to learn Haskell (thanks a lot to Chris Allen for laying out a path to FP enlightenment :)
I've worked through the first 4 weeks now, but I decided at this point to switch gears and go back to recap what I've learned so far.
Without further ado, let's recap CIS 192: week 1.
Haskell (named after Haskell Curry, for his work on combinatory logic and for the Curry-Howard Correspondence), is a lazy, statically typed, pure functional programming language created in the 1980's by a committee of academics. It's very well alive today, as it's one of the most advanced (statically typed) languages out there.
Haskell is:
Every expression is referentially transparent. This means that:
As a consequence of the previous points, calling the same function with the same arguments results in the same output, always.
This approach has a number of very nice benefits, that once you wrap your head around this paradigm you won't give away too easily:
In general, with static types and pure functions programs become much more easy to maintain, refactor, debug and reasoning about.
In Haskell values are computed only when needed (call-by-need evaluation strategy).
Advantages:
Downside: it becomes harder to reason about the time and space characteristics of programs.
The course revolves around thee key areas:
Static type systems can be annoying, and some of them really are. But this isn't because type systems are inherently annoying, that's because some of them are insufficiently expressive (for example, Java and C++ ones).
A type system (especially the Haskell one):
Once you start to get the hang of it, a (good) type system becomes an invaluable ally. It feels liberating, since it can help you long before you write the first line of code: it helps you in the design of the system.
In some way, designing and maintaining software is a battle against repetition: you frequently need to take similar things and factor out their commonality (a process known as abstraction).
Haskell gives you a lot of abstraction power: parametric polymorphism, higher-order functions, type classes, etc. Its type systems is also a powerful, methodic and sound tool to think mathematically about them.
Quoting Ralf Hinze:
“Functional languages excel at wholemeal programming, a term coined by Geraint Jones. Wholemeal programming means to think big: work with an entire list, rather than a sequence of elements; develop a solution space, rather than an individual solution; imagine a graph, rather than a single path. The wholemeal approach often offers new insights or provides new perspectives on a given problem. It is nicely complemented by the idea of projective programming: first solve a more general problem, then extract the interesting bits and pieces by transforming the general program into more specialised ones.”
In short, it's about working with abstractions rather than concrete instances of the problem/solution space, with group/types of things instead of with single instances.
Next, Brent Yorgey goes on showing the basic types (scalars and lists), how to define and combine functions, etc. Lots of good stuff.