Learn Haskell
Go to file
2014-06-30 19:42:21 -05:00
LICENSE Initial commit 2014-05-19 12:43:26 -07:00
README.md Mention community 2014-06-30 19:42:21 -05:00

This is my recommended path for learning Haskell.

Something to keep in mind: don't sweat the stuff you don't understand immediately. Just keep moving.

Community

Our IRC channel is #haskell-beginners on Freenode.

IRC web client here: http://webchat.freenode.net/

Primary course

What are Haskell, GHC, and Cabal?

Haskell is a programming language as laid out in the reports, most recent one being in 2010. http://www.haskell.org/onlinereport/haskell2010/

GHC is the most popular compiler for Haskell and is what you'll install along with Cabal. Cabal is the project and dependency management tool used with GHC. You almost definitely want both if you're going to start writing Haskell.

Cabal is equivalent to Ruby's Bundler, Python's pip, Node's NPM, Maven, etc. GHC manages packaging itself, Cabal chooses what versions to install.

Getting started

Ubuntu

This PPA is excellent and is what I use on all my Linux dev and build machines: http://launchpad.net/~hvr/+archive/ghc

Specifically:

  • sudo apt-get update
  • sudo apt-get install python-software-properties
  • sudo add-apt-repository -y ppa:hvr/ghc
  • sudo apt-get update
  • sudo apt-get install cabal-install-1.20 ghc-7.8.2 happy-1.19.3 alex-3.1.3

Then add ~/.cabal/bin:/opt/cabal/1.20/bin:/opt/ghc/7.8.2/bin:/opt/happy/1.19.3/bin:/opt/alex/3.1.3/bin to your PATH (bash_profile, zshrc, bashrc, etc)

Debian

Debian can follow the same steps as Ubuntu, but has to execute an additional command. Immediately after sudo add-apt-repository -y ppa:hvr/ghc is ran, run:

  • sudo sed -i s/wheezy/trusty/g /etc/apt/sources.list.d/hvr-ghc-wheezy.list

For other Debian versions, just replace all occurences of "wheezy" with your version name in the command above.

If, for some reason, the file /etc/apt/sources.list.d/hvr-ghc-wheezy.list does not exist, try the same command but with /etc/apt/sources.list instead.

Arch Linux

To install Haskell from the official repos on Arch Linux

Update your mirrorlist

  • sudo pacman -Syy

Download Haskell

  • sudo pacman -S cabal-install ghc happy alex haddock

Mac OS X

Install the GHC for Mac OS X app, which includes GHC and Cabal. It provides instructions on how to add GHC and Cabal to your path after you've dropped the .app somewhere.

Windows and other Linux users

Download the latest binary distributions for cabal and ghc:

GHC

GHC is the most popular way to work in the Haskell language. It includes a compiler, REPL (interpreter), package management, and other things besides.

Cabal

Cabal does project management and dependency resolution. It's how you'll install projects, typically into their own sandbox.

Detailed manual install guide for Mac OS X

You don't need this if you use the .app, but if it doesn't work for you, try this with the binary distribution.

Yorgey course - Do this first, this is the primary way I recommend being introduced to Haskell.

http://www.seas.upenn.edu/~cis194/lectures.html Brent Yorgey's course is the best I've found so far and replaces both Yann Esposito's HF&H and the NICTA course. This course is particularly valuable as it will not only equip you to write Haskell but also help you understand parser combinators.

Understanding basic Haskell error messages

Supplementary course that provides more material on intermediate topics

This is Bryan O'Sullivan's online course from the class he teaches at Stanford. If you don't know who he is, take a gander at half the libraries any Haskell application ends up needing and his name is on it. Of particular note if you've already done the Yorgey course are the modules on phantom types, information flow control, language extensions, concurrency, pipes, and lenses.

Development Environment

Emacs

Vim

Sublime Text

FAQ and working with Cabal

Fantastic FAQ

In addition to being an amazing guide for all kinds of things such as GADTs, this also covers some useful basics for Cabal

Cabal guidelines

Cabal Hell was a problem for Haskell users before the introduction of sandboxes. Installing outside of a sandbox will install into your user package-db. This is not a good idea except for foundational packages like Cabal, alex, and happy. Nothing else should be installed in the user or global package-dbs unless you know what you're doing.

To experiment with a package or start a project, begin by doing cabal sandbox init in a new directory.

Put briefly:

  • Always use sandboxes for installing new packages, building new or existing projects, or starting experiments
  • Use cabal repl to start a project-scoped ghci instance

The sandbox-based approach I suggest should avoid package-dependency problems, but it's incompatible with the way the Haskell Platform provides pre-built packages. If you're still learning Haskell and don't understand how ghc-pkg and Cabal work, avoid Platform and instead use the install instructions earlier in the guide.

Exercises for practice

You should do Yorgey's course before attempting this: https://github.com/NICTA/course/

Secondary material, references

Learn You a Haskell for Great Good (LYAH) and Real World Haskell (Thanks bos!) are available online.

I recommend RWH as a reference (thick book). The chapters for parsing and monads are great for getting a sense for where monads are useful. Other people have said that they've liked it a lot. Perhaps a good follow-up for practical idioms after you've got the essentials of Haskell down?

For learning some common typeclasses

Useful for understanding Functor, Applicative, Monad, Monoid and other typeclasses in general but also some Hask-specific category theory:

Search code by type signature

The Hoogle search engine can search by type:

http://www.haskell.org/hoogle/?hoogle=%28a+-%3E+b%29+-%3E+%5ba%5d+-%3E+%5bb%5d

Alternately:

https://www.fpcomplete.com/hoogle

Also Hayoo (which has all of hackage enabled for search by default): http://holumbus.fh-wedel.de/hayoo/hayoo.html

Setting up your own local instance of Hoogle

https://gist.github.com/bitemyapp/3e6a015760775e0679bf

Fun Stuff

After you're comfortable with Haskell, strongly consider learning Lenses and Prisms, even if just as a "user". You don't need to understand the underlying category for it to be useful.

Seen here: http://hackage.haskell.org/package/lens

Frontend/JavaScript

If you need JavaScript, you probably want Purescript for generating JS. Purescript is not strictly Haskell but it is very similar and quite pleasant.

Laziness, strictness, guarded recursion

let a = 1 : a -- guarded recursion, (:) is lazy and can be pattern matched.
let (v : _) = a
> v
1
> head a -- head a == v
1

let a = 1 * a -- not guarded, (*) is strict
> a
*** Exception: <<loop>>

Parallelism/Concurrency

Recursion Schemes

Some of the crazy *-morphism words you've heard are actually about recursion. NB - before tackling this material you should know how to implement foldr for lists and at least one other data structure, such as a tree. (folds are catamorphisms) Knowing how to implement an unfold (anamorphism) for the same will round things out a bit.

This material dovetails with traversable and foldable.

Lenses and Prisms

People vastly overestimate the difficulty of using Lens. Anybody comfortable with Functor/Foldable/Traversable (or even just the first one) can leverage lenses and prisms to make their life happier.

If you've ever done something like: (fmap . fmap) you were "lensing" in your head.

I recommend these two tutorials/introductions:

Dreaded monads and monad transformers

Do not do these until you understand typeclasses, Monoid, Functor, and Applicative!

Implement the standard library monads ( List, Maybe, Cont, Error, Reader, Writer, State ) for yourself to understand them better. Then maybe write an monadic interpreter for a small expression language using Monad Transformers Step by Step paper.

Writing many interpreters by just changing the monad to change the semantics can help convey what's going on.

Also, reimplement Control.Monad. Functions like mapM or sequence are good opportunities to practice writing generic monadic code.

The NICTA course can be used as a guide to this process, which will also involve writing your own Applicative as well.

From:

Type and Category Theory (not needed to actually write Haskell, just for those interested!)

If you want to follow up on the type and category theory:

Stephen's Nifty "How to get to monad" posts

Didn't know where else to put these:

Parametricity, ad-hoc vs. parametric polymorphism, free theorems

Initial and Final, DSLs, Finally Tagless

Comonads

Yoneda / CoYoneda

Dependent typing

Propositions vs. Judgments (computation)

Extended Reading list (some is already included here)