
How to Learn Haskell - octopus
http://acm.wustl.edu/functional/haskell.php
======
keyist
You can't have a "How to Learn Haskell" post without mentioning the
Typeclassopedia: <http://www.haskell.org/haskellwiki/Typeclassopedia>

For those going through LYAH, I highly recommend supplementing chapters 11-13
with this excellent resource.

~~~
johnbender
I cannot overemphasise how much easier it is to understand Monads once you've
groked Functors and Applicatives. It allows you to build an intuition for the
_general_ structure and purpose of the typeclasses instead of trying to start
with Monads by viewing them through the lens of IO or State.

------
Swizec
Learn you a Haskell for Great Good is definitely an awesome book to get a
handle on Haskell.

As the article says, it starts off from the basics and just quickly enough
builds up from there to wherever you want to go. I stopped once I got
distracted by writing useful-ish code :)

Also it's completely mindblowing, but irrelevant, that my high school
classmate wrote that book.

~~~
dudurocha
It's mind blowing thinking that he is still a undergrad student.

This book saved my life. In my Functional Programming class, all the students
have made though because of the book. Many cheers for him.

~~~
Swizec
It's even more mindblowing that he's still my classmate ... sort of. Everyone
flunks around so much at our faculty that it's hard to define what a classmate
is.

------
exDM69
I disagree with the order that this suggests learning stuff. The article
recommends first playing around in the functional subset of the language in
the REPL, then learn about theory of monads and finally put it into use with
IO.

I feel it's better to jump straight in to IO after doing some basics and
definitely before trying to learn deeper theory about monads. The second or
third exercise you write should have a little I/O in it, do something like a
guess the number or hangman game. I've found that it's also useful to first
write it normally using "do" notation and then manually transform it into
concrete syntax using ">>=", either mentally or actually writing it out
compiling/running. This is a very simple (1 to 2 hour) exercise but should
give a pretty good picture of what it's about.

This is a way to avoid the most common pitfall there is in learning Haskell,
"not getting monads". There are lots of people who learn the basics of
functional Haskell, but they are so afraid of the new concept of monads that
they cannot get to writing a real application. I've seen people get stuck in
this limbo for years.

Once you know enough I/O to open a file or run a simple loop, the horizons of
your Haskell programming projects are vastly extended. If you can read and
write files, you can get your hands on more and more interesting data to use
for your apps.

Of course, people are different. If you're the kind of person who enjoys
reading books about theory (and not the learning-by-doing type), just ignore
everything what I just said and go enjoy a book or a wikipedia article about
applicative functors, monoids or category theory.

(I don't know pretty much any theory about functors or monoids but it doesn't
stop me from writing parsers, compilers and 3d graphics tools using Haskell.
Just as not knowing theory about attribute grammars or LALR(1) parsers did not
stop me from writing stuff in C.)

------
neutronicus
This is a bit of a tangent, but can anyone provide an opinion on which of the
static-typing big 3 (Haskell, SML, OCaml) is most suited to scientific
computing?

~~~
monopede
That depends on the kind of scientific computing you want to do.

Haskell has the repa library [1] which is very nice for working with (multi-
dimensional) arrays at a high level. Performance is decent (I don't know if
they have a BLAS/LAPACK binding). Overall, the main advantage of Haskell is
its runtime system and its great support for concurrency. The downside is, it
does not have OpenMP and the MPI bindings don't look very nice to use (I don't
know how OCaml or SML fare in this area). There are OpenCL bindings, but I've
never used them. Data parallel Haskell is still under heavy development, so
that's probably going to take a few years to become production-ready.

OCaml's advantage is that C-like algorithms are easier to transcribe and use
(no monads). OCaml's main disadvantage is that its runtime doesn't support
multicore well (or even at all?). If you want that you can use F#, though.

I don't know anything about the current state of SML implementations.

[1]:
[http://www.haskell.org/haskellwiki/Numeric_Haskell:_A_Repa_T...](http://www.haskell.org/haskellwiki/Numeric_Haskell:_A_Repa_Tutorial)

~~~
srean
Answering a sub question of yours: Indeed the only way to use more than one
core in OCaML is to use multiprocessing. If there is a lot of data that needs
to be exchanged, it may not be very fast.

That said there is this patched up version (funded by a one off summer of code
by Jane street, I think)

<http://www.algo-prog.info/ocmc/>

that gives an API for using threads. I am fairly new to OCaML so will not be
able to provide details. Another language that I am looking at is Felix

<http://felix-lang.org:8080/> (Note the port, its not the one that the search
engines will give you).

I am ok with OCaML not giving its users a threading API but a runtime that
executes many of its higher-order functions in parallel would be really nice.
Well, higher-order functions and the other parallelism exposed by the
functional semantics, with some helpful directives from the user of course.

~~~
gtani
There's been a lot of projects, of which the ocamlnet/netmulticore and Jane St
async's are (I think, but not very confidently) the only current. Others are:

poly/ML, ocamlP3, OC4MC, functory, JoCaml

coThreads, LWT

[http://www.reddit.com/r/programming/comments/q9cro/real_worl...](http://www.reddit.com/r/programming/comments/q9cro/real_world_ocaml_book_on_ocaml_coming_in_the_fall/c3xu3xj)

[http://stackoverflow.com/questions/6588500/what-is-the-
state...](http://stackoverflow.com/questions/6588500/what-is-the-state-of-
ocamls-parallelization-abilities)

------
shurane
I don't know Haskell well. That said , this 'guide' is really blunt, succinct,
and informative about Haskell. It's rather nice and gives me a feel for the
language a lot quicker than "Learn You a Haskell" did.

And it's got a ton of references to existing resources in a ready to consume
fashion. I would've liked this a lot when I kept getting stuck on Monads.

------
dons
Nice. Wibble: it's 2012 - don't use Hugs. And just link to the Haskell
Platform to get an installer

~~~
Locke1689
Quick question, since we have an author of RWH here for the moment -- most
resources (including RWH) don't seem to mention Template Haskell or GHC type
extensions.

Is this because they're nonstandard or do you disagree with their use cases?
(For example, the section on Monad transformers in RWH is used similarly to
the way implicit parameters might be used if enabled).

~~~
dons
They come with GHC, but they're mostly not standardized. And there's more than
50 language extensions. They're not usually mentioned in texts, as they're
usually necessary only for advanced user, or very small niches.

However, if you're are medium to advanced Haskell user, you should know about
the common language extensions:

* GADTS * Template Haskell * EmptyDataDecls * ExistentialQuantification * GeneralizedNewtypeDeriving * KindSignatures * MonadComprehensions * QuasiQuotes * RankNTypes * RecordWildCards * Safe mode * TypeFamilies * ViewPatterns * UnicodeSyntax

Some of them have very good power to weight ratios.

Each extension has a niche it excels at, and knowing when to recognize that
you're in that niche takes time.

------
srean
Following up on <http://news.ycombinator.com/item?id=3825705> here because
that comment is already too deeply nested and it is too late to edit (nee
mutate) it in place.

There was some fear expressed in the thread that development on MLton might
have stopped, but going by this
[http://mlton.svn.sourceforge.net/viewvc/mlton?view=revision&...](http://mlton.svn.sourceforge.net/viewvc/mlton?view=revision&revision=7561)
(codegen bugfix checked in 6 weeks ago) it seems MLton alive and well, I am
definitely happier now that it is.

About its reasons for disappearing from the language shootout as mentioned
here <http://news.ycombinator.com/user?id=Locke1689> here is the explanation
from its list

<http://mlton.org/pipermail/mlton/2011-September/030962.html>

I read a thread about their plans to move their list to sourceforge. Maybe
that has not happened yet, that might explain why the last available mail-
archive is from Oct 2011.

~~~
mahmud
I have just picked up SML again after 10 years. SML/NJ is sharp .. I built it
with 2-3 commands and it even downloaded the extra sources it needed :-)

------
khwang
Thanks for the pointer! My first language was Scheme and I always kind of joke
around about eventually learning Haskell. I think I might actually start doing
it though.

~~~
octopus
You may also be interested in implementing Scheme in Haskell:

[http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H...](http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours)

~~~
tmhedberg
While that's an interesting read and fun mini-project, I wouldn't recommend it
as a tutorial for Haskell beginners. You need to have a pretty decent handle
on the language before a lot of it will make sense.

 _Learn You a Haskell for Great Good!_ is the ideal starting point, in my
opinion.

~~~
wging
_You need to have a pretty decent handle on the language before a lot of it
will make sense._

While that's true, I think a learner may need more to aspire to (whether to
_write_ it, or just _understand_ it) than just the next line of 'Learn You a
Haskell'.

And there's also the fill-in-the-blanks phenomenon: you see a bit of code and
have no idea what it does, but later on when you start to learn the underlying
idea behind that code it may help solidify your understanding.

This is also a good way to learn math: rather than a strict progression of
incremental steps, it's good sometimes to beat your head against something
that's way above your level. Even if it seems like you're doing nothing,
you're actually creating _a space in your head where this knowledge can go_ ,
if I can be forgiven that metaphor.

~~~
tmhedberg
Agreed. _LYAH_ is fantastic for forming a conceptual foundation, but if
there's one thing it lacks, it's exercises, so it's definitely a good idea to
supplement it with something more focused on writing actual code. _Write
Yourself a Scheme_ is good for that purpose, as is _Real World Haskell_.

------
Cieplak
Does anyone here have experience with HDBC? I am very interested in using
Haskell in a risk-rating system for cross-collateralized loans and bonds, but
I absolutely need solid support for working with Sybase and SQL Server. We've
used Clojure in our prototypes, and JDBC is top notch. However, Clojure lets
you get away with a lot, while Haskell forces a level of discipline and gives
a proper debugger. Also, I could really use Haskell's algebraic data types for
performing operations on relational data and applying rules that have lots of
exceptions. The system we're replacing is a mess of CASE WHENs and stored
procedures operating on views built on views. I'd really like to use Haskell,
but absolutely need solid database integration.

~~~
gaius
A few thoughts on HDBC: [http://gaiustech.wordpress.com/2010/09/19/scope-in-
database-...](http://gaiustech.wordpress.com/2010/09/19/scope-in-database-
code-2/)

Note that in practice, in OCaml, I found it easier to write my own Oracle
bindings than use the "standard" one: <http://gaiustech.github.com/ociml/>

The mainstream community of both Haskell and OCaml, I get the feeling, doesn't
really care too much about RDBMS access, as it's not something academics often
need, so you will often find yourself on your own if you have a problem. The
only mainstream functional language that does take RDBMSs seriously is F#,
which it gets "for free" as C# needs it.

~~~
Cieplak
Thank you very much. I've never seen such beautiful database code before. I
think it's here where the power of monads really shines; they keep all the
statefullness of the database from cluttering up the rest of the code. I will
stick with the JVM because of legacy integration. Although I must say, the
more I use Haskell, the cleaner my code in other languages gets. Haskell is
almost like poetry in this regard.

------
gtani
The Breadcrumbs are helpful, if you missed the links

<http://acm.wustl.edu/functional/hs-breads.php>

\------------

Note: most of the GHCi idiosyncrasies were ironed out in 7.4 but you can't
cut/paste code into it AFAIK:

<http://hackage.haskell.org/trac/ghc/ticket/4929>

[http://www.reddit.com/r/haskell/comments/kmxf2/ghci_now_supp...](http://www.reddit.com/r/haskell/comments/kmxf2/ghci_now_supports_all_toplevel_declarations/)

\-----------

HNers learning haskell:

<http://news.ycombinator.com/item?id=3122725>

------
bellbind
Why did I clicked that link? Now I can't help learning me a Haskell.

~~~
gtani
Haskell is like a venus flytrap, mwahaha

------
flypunk
I don't mean to troll, but the fact that the URL ends in php looks funny.

From [http://steve-yegge.blogspot.com/2010/12/haskell-
researchers-...](http://steve-yegge.blogspot.com/2010/12/haskell-researchers-
announce-discovery.html):

"MacFarlane concluded, "Our elegant approach didn't work, so we hired a Perl
hacker..."

