Tuesday, May 21, 2013

How to Learn Haskell

For whatever reason, Haskell's curve of interest has been going up again. Haskell is a philosophy as much as a language, and a controversial one at that. Haskell is lazy and purely functional language. I will explain what each of those are at the bottom of this article. This is more specifically about how to set up a good Haskell learning environment.

Learning Material
For learning Haskell, look no further than http://learnyouahaskell.com/. Learn You a Haskell is written in a similar manor to Land of Lisp with its quirky prose and downright hilarious examples. Due to Haskell's lack of wide use, this book has a near monopoly on the task of learning Haskell; which is fine. The book covers everything very in-depth. If there is something in here, you will need it to use Haskell effectively, so do not skip around, especially when the problems gets harder (like the RPN calculator). Extra learning material and support can be found in the sidebar of http://www.reddit.com/r/haskell/

Development Tools
Haskell is nothing without a good text editor. There are some relatively advanced formatting standards within Haskell (especially with guards: see below). The best editor for Haskell is subjective, but I will cover the tools that I have used for Haskell development and try to take an unbiased look at each one. Before reading the recommendations I have to come clean; I use Emacs, so I may lean towards it a little bit and compare a lot of the tools to Emacs.

     Eclipse FP
Eclipse FP is a plugin for the Eclipse framework that provides Haskell project support. Extra goodies can be installed via cabal (the haskell "package manager"). If you can get it working on your system with all of the recommended goodies (scion for syntax highlighting, ghc-mod for ghci integration, etc) then this could be a very easy and welcoming development tool. Drawbacks are the chance that it will NOT work (it didn't for me, but this was the first tool I tried to use. It's probably very good) and having to install Java as well as Haskell (~128 MiB in total).

Leksah ("Leck - Sah", Haskell backwards) is  full-blown Haskell IDE written in yours truly (Haskell). It has some interesting features, like listing the type signature of a function when you type it (think: Javadoc lookup in other IDE's) and trying to compile the file on every keystroke, showing you (and underlining) when you make a mistake. It supports editing of Cabal files, project browsing, and graphical integration with the Haskell debugging tools. For serious Haskell users, consider Leksah. I found that it is too early in its development to be useful to me (I experienced several crashes without file saves, but this may not happen to you), but the amount of tools this brings into one project makes it enticing if you really want to get your hands wet with Haskell. Since this is a post about learning material, I don't think that this would be appealing. 

One many in my IRC channel said that Emacs is "Not an editor, but an operating system with a [censored] good editor". Emacs has been around for a long time and is very extensible, which means it has a lot of tools written for it. This is perfect, because Haskell matches this description very well. To make Emacs useful with Haskell, one first must install el-get  and then use el-get to install haskell-mode, ghc-mod, and scion. Be sure to add the appropriate code into your .emacs file. 

The benefits to using this is that C-c C-l will load a file into a ghci minibuffer, which is great for testing out programs on the fly as well as saving them for compilation later. Yes, Eclipse has features like this, and so does vim with the right plugins, but Emacs and these extensions happened to hit my sweet spot. Look around and see what is right for you. in this department. Emacs can also extend into an IRC client, so asking for help on #haskell on Freenode is very simple.

Learning Strategy
Haskell is overwhelming to many. If you do not know a functional language already, it may even be wise to learn a bit of Common Lisp before using Haskell. Haskell is purely functional. There are no loops or IO outside of the IO Monad, so it is a major forced paradigm shift. I would learn enough Haskell from "Learn You A Haskell" to be able to work on projects (pattern matching, functors, etc), work on some, and go back to where you left off to finish up your learning. Learn You A Haskell is a very in-depth book and without the context of some projects it will all get jumbled.

No comments:

Post a Comment