[haskell] Getting started with Haskell

For a few days I've tried to wrap my head around the functional programming paradigm in Haskell. I've done this by reading tutorials and watching screencasts, but nothing really seems to stick. Now, in learning various imperative/OO languages (like C, Java, PHP), exercises have been a good way for me to go. But since I don't really know what Haskell is capable of and because there are many new concepts to utilize, I haven't known where to start.

So, how did you learn Haskell? What made you really "break the ice"? Also, any good ideas for beginning exercises?

This question is related to haskell functional-programming

The answer is


If you only have experience with imperative/OO languages, I suggest using a more conventional functional language as a stepping stone. Haskell is really different and you have to understand a lot of different concepts to get anywhere. I suggest tackling a ML-style language (like e.g. F#) first.


I'd suggest joining the #haskell irc channel and asking questions there. That's how I learned Haskell. If you go through Real World Haskell as suggested above, real time answers to your questions will help greatly. Lots of smart people on #haskell write Haskell for fun and for profit, so you'll get lots of good input. Try it!


The first answer is a very good one. In order to get to the Expert level, you should do a PhD with some of the Experts themselves.

I suggest you to visit the Haskell page: http://haskell.org. There you have a lot of material, and a lot of references to the most up-to-date stuff in Haskell, approved by the Haskell community.


I can additionally recommend Yet Another Haskell Tutorial as an introduction.

Another good learning resource (probably on the intermediate level), which has helped me a lot and hasn't been mentioned in the other answers as far as I can see, is Brent Yorgey's Typeclassopedia, which can be found in The Monad Reader (Issue 13)

It is written in a very accessible style and contains (among many other things), the following introductory advice:

There are two keys to an expert Haskell hacker’s wisdom:

  1. Understand the types.

  2. Gain a deep intuition for each type class and its relationship to other type classes, backed up by familiarity with many examples.

The Monad Reader itself is an absolute treasure trove for functional programmers (not only Haskell programmers).


I enjoyed watching this 13 episode series on Functional Programming using Haskell.

C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals: http://channel9.msdn.com/shows/Going+Deep/Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1/


Don't try to read all the monad tutorials with funny metaphors. They will just get you mixed up even worse.


I do think that realizing Haskell's feature by examples is the best way to start above all.

http://en.wikipedia.org/wiki/Haskell_98_features

Here is tricky typeclasses including monads and arrows

http://www.haskell.org/haskellwiki/Typeclassopedia

for real world problems and bigger project, remember these tags: GHC(most used compiler), Hackage(libraryDB), Cabal(building system), darcs(another building system).

A integrated system can save your time: http://hackage.haskell.org/platform/

the package database for this system: http://hackage.haskell.org/

GHC compiler's wiki: http://www.haskell.org/haskellwiki/GHC

After Haskell_98_features and Typeclassopedia, I think you already can find and read the documention about them yourself

By the way, you may want to test some GHC's languages extension which may be a part of haskell standard in the future.

this is my best way for learning haskell. i hope it can help you.


Here's a good book that you can read online: Real World Haskell

Most of the Haskell programs I've done have been to solve Project Euler problems.

Once piece of advice I read not too long ago was that you should have a standard set of simple problems you know how to solve (in theory) and then whenever you try to learn a new language you implement those problems in that language.


Graham Hutton's Programming in Haskell is concise, reasonably thorough, and his years of teaching Haskell really show. It's almost always what I recommend people start with, regardless of where you go from there.

In particular, Chapter 8 ("Functional Parsers") provides the real groundwork you need to start dealing with monads, and I think is by far the best place to start, followed by All About Monads. (With regard to that chapter, though, do note the errata from the web site, however: you can't use the do form without some special help. You might want to learn about typeclasses first and solve that problem on your own.)

This is rarely emphasized to Haskell beginners, but it's worth learning fairly early on not just about using monads, but about constructing your own. It's not hard, and customized ones can make a number of tasks rather more simple.


These are my favorite

Haskell: Functional Programming with Types

Joeri van Eekelen, et al. | Wikibooks
       Published in 2012, 597 pages

Real World Haskell

   B. O'Sullivan, J. Goerzen, D. Stewart | OReilly Media, Inc.
   Published in 2008, 710 pages

Some colleague of mine had good experience with Learn You a Haskell for Great Good!.

Tutorial aimed at people who have experience in imperative programming languages but haven't programmed in a functional language before.

And check the answers here too


Try writing easy programs in it.

You can find sample tasks in various textbooks, probably.

I wouldn't recommend sticking to Haskell/FP textbooks, just try to do simple things with it: calculations, string manipulations, file access.

After I solved a dozen, I've broke the ice :)

After that, read a lot on advanced concepts (Monads, Arrows, IO, recursive data structures), because haskell is infinite and there are a lot of them.


I suggest that you first start by reading BONUS' tutorial, And then reading Real World Haskell (online for free). Join the #Haskell IRC channel, on irc.freenode.com, and ask questions. These people are absolutely newbie friendly, and have helped me a lot over time. Also, right here on SO is a great place to get help with things you can't grasp! Try not to get discouraged, once it clicks, your mind will be blown.

BONUS' tutorial will prime you up, and get you ready for the thrill ride that Real World Haskell brings. I wish you luck!


To add on others' answers - there is one useful that will help you when coding (for example when solving project Euler problems): Hoogle. You can use either the command line interface or the web interface.

Command Line

After you installed the Haskell platform be sure to cabal install hoogle

Hoogle usage example:

You have a function f x = 3 * x + 1 and you want to apply it on (5 :: Int), then apply it on the result and on that result and so on and get an infinite list of those values. You suspect there might already exist a function to assist you (not specifically for your f though).

That function would be of type (a -> a) -> a -> [a] if it takes f 5 or a -> (a -> a) -> [a] if it takes 5 f (we assume the function is for general types and not just Ints)

$ hoogle "a -> (a -> a) -> [a]"
Prelude iterate :: (a -> a) -> a -> [a]

yep, the function you need already exists and it's called iterate. you use it by iterate func 5!

Web interface

The result for the same example can be found here.