How to Learn Haskell
acm.wustl.edu
acm.wustl.edu
For those going through LYAH, I highly recommend supplementing chapters 11-13 with this excellent resource.
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.
This book saved my life. In my Functional Programming class, all the students have made though because of the book. Many cheers for him.
As soon as you start developing a serious application in Haskell, though, I've found you eventually need to jump back to Hudak's Gentle Introduction to Haskell[1], the Haskell 98 Report[2] (I suppose the 2010 report works too, but I haven't used it as a resource nearly as much), and Hoogle/Hackage for the Haskell source of any library which you want to use seriously.
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.)
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...
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.
poly/ML, ocamlP3, OC4MC, functory, JoCaml
coThreads, LWT
http://www.reddit.com/r/programming/comments/q9cro/real_worl...
http://stackoverflow.com/questions/6588500/what-is-the-state...
Haskell is usually about 1-10x slower than C for the same task, while MLton has actually outperformed C in some benchmarks.
Edit: My information is out of date -- dons is almost certainly right on this one. I'd go with his estimation.
http://mlton.org/cgi-bin/viewsvn.cgi/mlton/branches/llvm/#di...
but have no idea how functional (aargh! no not that functional) it is. There seems to be some activity on the trunk in the last 7~8 months, but possibly maintenance edits. Just putting it out there if anyone wants to poke. It would be sad for MLton to bit rot.
http://shootout.alioth.debian.org/u32/which-programming-lang...
If you do a lot of matrix computations, for example, you can always call a fast Fortran library like Blas or Lapack through a C layer.
OCaml is probably the most pragmatic of the three, but the parallelism and concurrency story is pretty weak. There is a book, OCaml for Scientists, which is a tutorial intended for the scientific audience though. It's also heavily used in finance. It also compiles quite fast.
Haskell is the hardest of the three to learn and get up to speed with. If you have a heavy mathematical bend, it may make the most sense. Parallelism and concurrency are simple and easy, but I don't know if you can do MPI or OpenMP style supercomputing; it really seems optimized for desktop/server processors.
I love SML for its simplicity, clarity and power, but it is essentially a dead language at this point, with most of its userbase having migrated to Haskell or OCaml. I don't know if Concurrent ML supports true SMP, but that would leave you limited to certain implementations. MLton is fantastic, but it comes at a price of very slow compiles with no separate compilation.
If I were in your shoes, I'd look at some sample code in OCaml and Haskell and see which one looks more reasonable, and then write a small program in each and see which one you like the feel of more. You're probably going to run into a sticky spot at some point in your project whichever one you choose; the more you like the option you have, the more likely you are to stick it out.
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.
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).
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.
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&... (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.
http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H...
Learn You a Haskell for Great Good! is the ideal starting point, in my opinion.
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.
Reasons: in the context of Postgres, the above lib allows you to do full sql with proper escaping of parameters and also is extensible with respect to defining how to serialize values to and from the db side representation.
Full disclosure: I'm using that lib because it's the only one that lets me exploit postgres' geometry functionality while still using a rich query api thats type safe
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.
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...
-----------
HNers learning haskell:
From http://steve-yegge.blogspot.com/2010/12/haskell-researchers-...:
"MacFarlane concluded, "Our elegant approach didn't work, so we hired a Perl hacker..."