So, I decided to teach myself something new. Something exotic. I wanted to try a new paradigm and a language that is different from those which I am very familiar with while still being a usable language. I chose Haskell and ended up coding pretty much the entire easter holiday since my girlfriend was sick and we cancelled most of the usual family dinners. This is a look back at my quite intensive experience over the weekend. It’s less about the language itself, and more about the process of trying to learn it.
Because it is a totally different language, and because it is a pure language. That is, you really can’t work around the fundamental paradigm of this functional language like you can in other languages. You pretty much have to get into a different mindset and think differently. It also has a strong community and a certain buzz around it. This review is obviously from a very personal perspective and full of soft things like opinions. Everything here is also written from the perspective of a windows user. If your opinions differ, please do comment!
Haskell is pretty welcoming in this regard. I downloaded the Haskell platform, pressed install and it pretty much worked out of the box. By working I mean the compiler works and the cabal package installer works. This is a very good point, since if this would have taken all day I probably would have given up. Time is precious to me, and mucking about with the pure fundamentals isn’t what I’m interested in.
However, Haskell is lacking one thing in particular and it’s a really strong IDE. There is one, Leksah which I tried, but the auto-completion and syntax highlighting didn’t work like I wanted it to work. And by that I mean it would work pretty much exactly like ReSharper. I can’t stress this enough. A good IDE is an exploratory tool for a total beginner, it will give you useful error messages, it will suggest things which are correct and help you out. Haskell doesn’t have this. From what I gather many use Emacs and those sorts of editors. I’m sure they are good if you know how to use them, but a new editor as well as a new language is a bit much. I initially searched for a Visual Studio language extension, which apparently doesn’t exist. If this would exist it would have shortened my learning time considerably, taking away much frustration and wasted time.
In the end I ended up using Sublime text for editing Haskell, due to good syntax highlighting and a nice colour scheme.
There’s a lot! Seems that the converts are really eager to spread the Haskell gospel to the rest of us. A few stick out in particular, Learn you a haskell for great good and Real world haskell. They approach the learning differently, the first walks you through language features and shows you how to use them and the second one tries to do the practical thing. Also, I’d like to point to this post on stack overflow which really gives a nice clear path to follow.
I decided to do as the SO post said and do the 99 problems thing and keeping these two as a reference. Turns out this was a good idea. I’m learning by doing and doing these exercises was both fun and educational and sufficiently challenging to keep it interesting. Not all of the exercises are really suitable for Haskell learning and could do with a rewrite. Especially the random number exercises which are silly for a beginner to do in Haskell. Once this was exhausted I continued doing Project Euler problems, doing I think 15 of them.
I have mixed feeling about Project Euler. On one hand it’s really fun in a nerdy way. On the other hand the exercises quickly evolve into not coding together a solution for problem but either optimizing a solution to run fast enough to be practical or to mathematically analyze a problem in order to make it simpler. Optimizing Haskell is hard for a beginner, since the normal techniques won’t work or isn’t available at all, and doing the math analysis won’t make you better at Haskell.
The fabled community is very helpful indeed. Ask a question on the IRC channel and you’ll get answers in seconds. Ask on stack overflow and you get exhaustive answers immediately. At least to the beginner issues, I have no idea if this continues up to advanced stuff as well.
Hoogle is good, but a bit difficult to use for a total rookie. It increases in value all the time to me.
Making a project
When I realized that I was no longer learning Haskell from the Project Euler exercises I decided to go and do something on my own. My usual goto is graphics programming and this time I decided to do 2D-metaballs. This was a good exercise and took me most of a day to produce a working, if somewhat slow implementation that renders using the provided OpenGL bindings. The hardest thing here was the IO thing, especially since I didn’t (and still don’t) understand monads.
To a novice, Haskell feels like two languages. The functional one which is pretty easy to grasp and the monadic weird imperative language. A week has passed now and I think I understand a little bit more of why the code looks like it does, but it remained a mystery through most of the development. The finished project is on GitHub for the world to see and chuckle at. It runs slower than it should but I really don’t know why. I think it computes things too many times, but I don’t know how to optimize it yet.
A second project
I decided I wanted to do a raytracer, that draws a picture into a window. This proved hard but not for the reasons which I expected. Windows is apparently a second-class citizen in the Haskell world when it comes to libraries which requires interop with C. Haskell comes with a pretty brilliant package managed called cabal. In theory you should be able to just do
cabal install whatever-package. This works as long as the package is pure Haskell. I really loathe multiple click installs, and to get SDL running is a joke on windows! Here is obviously work to be done to make this friendly to anyone.
I can spend stupid amounts of time struggling with the language itself, but I get pretty pissed off at fiddling with the environment for more than a few minutes. This is also, by the way, the reason I won’t administrate servers or even fiddle with their settings to any real lengths.
So, I decided to just write a picture to disk instead. This also proved somewhat difficult, again due to the missing IDE. I found a promising library, but I can’t seem to find instructions on how to actually use them. cabal will install it, but it is missing examples. And this is my current status so far, since the easter weekend is over. I’m sure the API usage is somewhere in Hackage, but hell if I know how to use that thing properly to figure out what calls are available and what parameters they expect.
Haskell is a cool language and while it takes time to grok all the stuff in it. I’m not really qualified to talk about what is good and what is not in the language itself, but the purity of the thing is a very nice challenge and it will expand the horizon of any imperative oriented programmer out there. I like the language and the things it teaches me. It is definitely worth taking a weekend to do a test project. I also really like the compactness of the code, and the way the type system works. I have a long standing aversion to weakly typed languages, and Haskell is the antithesis of that.
Will I use it professionally? I’d like to do things in it, but I doubt that I’ll have the opportunity. While Haskell has come a long way in user friendlyness it still has a way to go in the tooling department for a typical windows user. The threshold for getting your feet wet and doing simple programs is low, but it feels like it is a steep step to doing something that is an actual real world thing in the windows-.NET-centric environments I work in. Can I get it to run easily in an IIS server or can I make windows applications or windows services easily in it? If the Haskell community could make those easily available to me the chances would be much improved.
And I hope they do improve, cause the feeling of coding Haskell when you have flow is one of the coolest things in the world. I got a little sense of it, and the power at your fingertips in this language makes you feel like a wizard.