A review of my Haskell adventure

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.

Why Haskell?

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!

Getting started

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.

Resources

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.

Final thoughts

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.

About these ads
Tagged , ,

11 thoughts on “A review of my Haskell adventure

  1. Pydev with eclipseFP is a pretty good Haskell IDE

  2. Sorry, meant Eclipse with EclipseFP !!!

  3. pjmlp says:

    While it is not Haskell, you can give a try to F#. At least you might be able to use it eventually on your .NET projects.

    • Per Dervall says:

      I debated that with myself, but decided against it since I felt that I would get the most benefit from being forced to use a pure functional paradigm by haskell than having what essentially amounts to a multi-paradigm language where I could cheat if I wanted to.

      That being said, your comment holds true that F# would probably be much more useable in a proffessional context. Though I doubt that the customers would like me using it. They probably rightly prefer a coherent codebase all written in one language. (I work as a consultant)

      I have continued to do some stuff in Haskell for kicks, I hope that further experience with it might place it in context, so that I can get some real-world useabilty out of it as well. If not, then at least I’ve gathered some valuable knowledge along the way.

  4. Ywen says:

    Concerning SDL, it’s perfectly normal that cabal doesn’t do anything wrt it: it installs a binding, not the lib, because the way to install it is completely dependent of your OS.
    So you need have the headers and DLLs already installed and accessible through your PATH, yes.

    What you want is the power of a package manager, and it feel weird because as a Windows user you should be used not to have one ;)

    • Ywen says:

      That being said, I agree the SDL binding for Haskell should have a better packaging.

    • Per Dervall says:

      I get your point, it’s outside the responsibilities of cabal, I agree with that.

      It’s probably more of a reflection on the status of SDL installation on windows than cabal itself, which actually works pretty good. I’m contrasting it with NuGet which is sort of the same thing as cabal but for .NET. Those libraries are almost always self-contained, though the .NET platform is pretty comprehensive so that you never need to install something beyond the actual library itself. I don’t think I ever have been required to install a supporting package when using that, and I’ve been using NuGet a lot.

      And, I’m not really a typical Windows user. I’m actually very comfortable using Linux and its package managers, the shell, perl, nano and whatnot. I did so for quite some years professionally :) I may be a windows centric developer though, which is a more accurate description.

      The most annoying thing in the world is probably the PATH in windows. Seriously. Either they make it totally unneccessary and fix me installers for everything, or they make it easy to edit it. Today it is neither.

      • Ywen says:

        Yes but I guess NuGet works only on Windows, hmm? Which makes easier for him to bundle/install third libraries as it only has to target one platform.

      • Per Dervall says:

        Yes, I think so. And, NuGet is a glorified file unzipper. Whatever you put in the package gets unzipped into a folder relative to your application. You can put pretty much what you want in it, including native dlls. So, it has a completely different arena to work within.

  5. […] is sort of a follow-up on my previous post about my adventure with Haskell. In retrospect, I’m happy I wrote my experience down since […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: