People ask me a lot how they can best get started with programming, functional programming, or Haskell specifically. I have tried here to put together a list of free resources to help you get started, things that I’ve used and feel confident are pedagogically sound. It’s an opinionated collection. It might not be perfectly suited to your needs, but these are things that worked for me.
What to do first
OK, you’re here looking at a Haskell-ish blog already so maybe you don’t need this advice. But. Just in case.
Unless you already know what you’re doing, I recommend following the minimal installers instructions here.
It’s worth noting that the word “Cabal” around the Haskell community refers to two things: one is a framework for building Haskell packages, while the other is a command-line interface for building and installing packages. While neither is technically essential, it’s good to take some time to familiarize yourself with both. You may sometimes hear talk around the Haskell community of “cabal hell,” but due to recent improvements in the
cabal-install package, this is expected to be a thing of the past.
If you are itching to write some Haskell, try Writing Simple Haskell. Use it along with its mate, Reading Simple Haskell, as both a great introduction and a great review/reference to basic Haskell structure and syntax.
When we’re talking about learning resources, I am very opinionated. In the course of writing a Haskell book, I have read most of the other Haskell books. I recognize that not everyone’s judgments here will be the same as mine, but these are what worked best for me (totally new programmer with not a lot of math background):
Get Programming with Haskell by Will Kurt: I bought this book a while ago and had been reading things out of order, picking chapters that seemed interesting. Since I already knew Haskell when I bought it, that worked for me. But recently I started reading it from the beginning in order to better evaluate it, and I really love it. The book says it assumes some prior programming experience, but I don’t think that it assumes very much, especially in the earlier chapters, although if you’re not already experienced at imperative or “object oriented” programming, then the (very well written) explanation of how functional programming is different from that might not mean too much to you. What puts this book over the top for me is that Kurt put a lot of thought into making the exercises actually interesting. He explains in the introduction that he’s more interested in “fun experiments that let you explore the world with this impressive programming language”, and, in my opinion, it shows. In the earlier chapter, some of the exercises are not “fun” perhaps, but later in the book, especially, he has had some fantastic exercise ideas, and I’ve really learned a lot from them – not only about Haskell, but they also helped me fill in some of my missing knowledge about programming per se. It’s not a free resource, but it is worth the money, and Manning frequently puts it on sale.
A Type of Programming by Renzo Carbonara: This book is quite different from anything I’ve ever read about programming before. There aren’t any exercises, which is, in my opinion, a real drawback to it; however, the writing style is engaging, clear, and approachable. Each chapter leads naturally, in a narrative style, to the next, which makes the introduction of even seemingly esoteric ideas like parametricity seem natural. It is written particularly for people who have no prior programming experience, and it gracefully makes Haskell look like the most natural and welcoming thing in the world. Well, this is my opinion of it, as someone who had no programming experience before I learned Haskell. This book is also not free, but it’s worth the money and instead of supporting a big corporate publishing company, you’re supporting Renzo directly, and he has given us many excellent open source Haskell libraries, so it’s doubly worth it.
I’m going to also toot my own horn here and recommend Finding Success (and Failure) in Haskell. This book is not designed for people who have no programming experience, and it might be considered quite challenging for people who have seriously never looked at Haskell before. However, it starts from conditional expressions (
else) which most programmers are probably familiar with and by looking at what it means that all values in Haskell have a type and moves through iteratively refactoring a program that validates passwords and usernames, along the way introducing and giving you practical experience with several of Haskell’s most important concepts. There will be further similar monographs coming from the Joy of Haskell house – each exploring a single topic in depth, so you can pick and choose the topics that interest you most or fill just the right gap in your Haskell knowledge. If you are interested in having access to these books as they are written and also have a network of reference pages about the topics covered and other Haskell topics, may I recommend a Type Classes membership?
Monday Morning Haskell is, honestly, one of the great unsung heroes here. I rarely hear people talking about and yet I consult it all the time! It has a swift but solid introduction to Haskell and also covers advanced topics such as machine learning in Haskell.
A lovely troupe of Australians have put together the Data 61 course. It is is essentially the newer, more complete and better designed NICTA course. Where the NICTA course could be fairly intimidating for new programmers, the one retains the ambitious, challenging bits but provides more of a gradual slope and structure. My best recommendation for most people is either to work through it with a mentor who knows Haskell or to work through it while reading or working through supplementary material; however, there are also some videos on YouTube that correspond to sections of the course that may be enough for motivated solo learners. It’ll help if you’re already comfortable asking for help on IRC or the like.
Haskell Wikibook: The wikibook is free, which is awesome, and it really starts from the basics and works its way up in a nice progression. It has some exercises, although you’ll want more. You can get more exercises by doing cis194, the 99 Haskell Problems, and the NICTA course, among other things. All of those are free. The wikibook does have uneven coverage – some topics aren’t covered enough and some parts are not as well written as others, which just follows from it being a wikibook. However, I found many parts of it very clear and reasonably easy to follow.
For people who have programming experience and are looking for something like the Haskell equivalent of Go by Example or the like, try the Haskell Phrasebook. Yes, I am absolutely tooting my own horn again, although not really because I have written a few of its pages but not most of them. It is, rather, the pet project of my partner Chris Martin and also accepts and publishes community contributions.
No Monads for You
A lot of people who have experience programming in other languages think the big thing they need to learn about Haskell is monads and try to start there. So, here are my suggestions for beginning monads:
If you really can’t wait, try this post.
And then follow it up with Pat Brisbin’s Maybe Haskell.
In other words, I really don’t think this is how you should try to start learning Haskell. Monads are best learned through usage and experience. Forget the word exists, forget what you’ve heard about it being impossible to “do I/O” in Haskell without monads.
Blog Posts and Tutorials
Good, good, now that you’ve decided to forego learning about monads until later, here are some blog posts and tutorials from around the web that I found helpful. Even if you are working through a book, getting the same lesson presented differently, with different wording and examples, can help. I try to keep this updated so that the links that are here all work, but if you find one that doesn’t, please let me know! This an absolutely biased and opinionated list, but if it’s listed here, it means I read it and found it helpful at some point in learning Haskell. Sometimes I still read posts that cover “basic” topics and learn from them, because each writer manages to touch on slightly different points or bring a fresh perspective to something. It’s great! Fill the cloud with code tutorials!
Some of the posts listed here go beyond basic function application and types. You may find you only understand half the post the first time you read it (or less sometimes, if you’re like me!). That’s cool. What I did is bookmark them and keep coming back to them as I learned more and I was able to recognize how much progress I was making by seeing how much more I understood each time.
We made a types cheat sheet available as a reference for understanding and reading Haskell datatype declarations and type signatures.
There is also a Haskell Cheat Sheet available in several formats, which is a nice touch. It may be more useful for reference/review than learning as a beginner, but it’s nice to have around anyway.
Function Application and Definition This one covers a lot, but there is a ton of examples that help if you follow along with them.
Haskell Functions Take One Argument Well, speaking of terse, Tony Morris can be a bit terse himself, but I think this post makes its point clearly. I believe it can seem like a pedantic point to beginners – that Haskell functions have only argument – but understanding it well is important to understanding partial application, which is ubiquitous in Haskell code.
Types & Kinds Again, a lot of examples here to help you understand the points.
The Algebra (and Calculus) of Algebraic Data Types This post is a good introduction to talking about algebraic data types. It does get into some things that don’t matter as much for programming Haskell but will help you understand how Haskellers talk about types and why.
Currying is Delicious I wrote this one, and like some of the ones above, it goes a bit beyond reading basic type signatures. But it’s important to understand currying, and as you get around to understanding kind signatures as well, it’ll help you understand functors, which will eventually help you understand the legendary Monad.
The Haskell Wiki is, like most wikis, uneven in quality and helpfulness, but this page has some nice tips and explanations of some common syntactic mistakes.
A nice concrete example of what recursion is, including the base case.
I also like these two posts from John D. Cook about recursion: Understanding Recursion and Understanding Recursion Part II. “Recursion is about solving a problem in terms of smaller versions of itself.” I am going to disagree somewhat with Cook and, apparently, Paul Graham (if I may be so bold), and say that I did find it helpful to trace the invocations of recursive functions a couple of times, but it’s quite correct to say that once you understand what’s going on, you will suddenly find that you almost never write recursive functions yourself and so you don’t think about the process anymore. Instead, you just use
mapor a fold or something and the recursion is built in. Well, at any rate, I found understanding the step-by-step process of how recursive functions work helped me understand what those functions were really doing, especially with folds.
Interactive Demonstration of
I haven’t worked through all the posts in this baseCS series (plus I always appreciate a clever title!) yet, but I have loved the ones I have. She has written posts on fundamentals like understanding hexadecimal and linked lists, through databases and fun topics like parse trees and the traveling salesman problem.
If you don’t already know git, you need to. One thing I’d like to note, because this wasn’t very clear to me for a long time, is that git is not GitHub. I use git mostly from the command line, so for me, when I move a repository from GitHub to Gitlab (or vice versa), I change the address of what I’m pushing to and pulling from, but the commands themselves don’t change. The first time I moved something from GitHub to Gitlab, I didn’t realize that would be true, and I thought I’d have to learn new things. Every experienced programmer is probably shaking their heads at me now, but if putting this out in public will prevent any one person from having the same fear, then so be it. That said, I highly encourage you to learn git from the command line. Here are some places to get started.
Read this first, because it’s reassuring and also has links (at the bottom) to the two best sources of understanding git’s underlying model that I know of. I don’t have a preference between them. I strongly urge you to familiarize yourself with the underlying structure of git. Having that model in your head will help you diagnose problems when they arise and use a search engine to find commands that you need. It’s hard to search for git commands if you’re not sure what you need to do, and having an idea of the underlying structure helps you know what you need to do.
This doesn’t explain very much about git’s underlying model, but is a good, quick starting point that explains the most commonly used commands, and it’ll serve as a good reference as you’re learning.
This is a solid introduction to rebasing. My only regret here is that it’s not called “Rebaser” after the awesome Pixies song. Anyway. You may not want to know about rebasing, and you may not like rebasing, but it is something you will probably have to know about at some point, and this is a good explanation.
Let’s talk about git problem-solving. This is about solving a problem you might never have or not have for a long time, it’s true. So why beginner? Because it explains a process for how to solve a problem using terminal commands and git that actually teaches you some useful and valuable things about terminal commands and git that you can use for other purposes, too. It’s not the first thing you should read to learn git, but when you’ve got some of the basics down and are looking to learn more, this one is good. (p.s. MJD’s blog is generally a goldmine of knowledge made accessible.)