Fork me on GitHub
I'm a programmer of various languages living in London

Further Haskell exploration

by

Today I decided to embark on an exploration of Haskell web development. I have previously bootstrapped a basic Snap setup but never got into actual hacking. Today I decided to give Yesod a go. I ran into a number of difficulties that drained away all my spare time this evening but in the end I feel like I’m ready to dive in tomorrow.

I started off by attempting to install Yesod, with a simple cabal install yesod. This command took about 10 minutes to finish compiling dependencies on my ThinkPad X61 before it died with an error. The problem seemed to be the version of haskell-platform was rather out-of-date, meaning a tool, called alex was too old for Yesod. To solve this rather small issue I took the rather drastic step of upgrading Ubuntu on the ThinkPad to Precise Pangolin because this includes the latest haskell-platform…and its all new and…just because! This is Ubuntu after all - trigger happy upgrades are the name of the game.

Meanwhile, in Mac land. While that upgrade was running I tried to run the new yesod web app on a Mac. Unfortunately I ran into all the problems I’ve encountered before with cabal-dev on OS X.

Firstly there’s some weirdness with cabal-dev being set to install everything in the system library location. This just makes no sense for cabal-dev - the whole point is for it to install libraries in a vendored, per-project location - not interfering with system libraries. It manifested itself as asking for a password all the time (turn on verbose -v3 to see it running all cabal commands with sudo - O_o). To fix that you edit the config file, outlined in a blog post I found. Annoying.

Another problem I had was ghc/ld spamming the terminal with loads of linker warnings. This really slowed down compilation. I didn’t really solve this (happened on my Mac Mini - didn’t happen on my work MacBook Air). I remember having to set options for GHC to silence that crap, but I forget the details…

In order to get it all working on my Mac I:

  • Uninstalled haskell-platform (this is homebrew installed for me)
  • Re-installed haskell-platform
  • cabal installed cabal-dev, yesod

Everything worked then. There’s also strange voodoo you have to run to unregister old packages - brew info haskell-platform splits out the necessary commands.

After all that, things worked…mostly. Currently there seems to be some car crash of dependencies caused by a new release of something called tls-extras. A helpful stranger in IRC (#yesod) told me to cabal-dev install tls-extra-0.4.2.1 - this forces a working version of that library and then you can happily install yesod and everything’s groovy.

Who said Haskell was difficult? Not me.

So now I have a skeleton Yesod project up and running and it’s all looking very promising. The helper script for creating projects gave me some confidence - specifically asking if I wanted sqlite, postgres, MongoDB or nothing seemed pretty good to me - this doesn’t appear to be a web framework/persistence system tied to a particular way of doing things.

The main reason why I decided to dive into Yesod however was the high volume of interesting yesod-related blog traffic - this is a pretty crucial metric in gauging the health of a library community in my opinion and my RSS reader has been bombarded with posts about it so I felt I had to see what all the fuss was about.

Hopefully happy Haskell hacking henceforth

Learning Haskell

by

So I have started to learn Haskell (again - I learned the basics at university for the Functional Programming class and loved it, I have since forgotten most of that).

Haskell is weird

When you first start out learning this language - or even just read some articles about it - the first thing that will strike you is that it seems completely obscure. The syntax is obscure, the concepts are obscure, but most of all - the language used to describe what things are is incredibly obscure. Every programming language community has evolved its own lingo of course and Haskell’s is awash with mathematics. If you subscribe to the planet Haskell RSS feed you will get the impression that Haskell is pretty much just an extension of Mathematics and is only used for “pure” problems and therefore completely irrelevant to real world problems. Then you will notice there’s a book called “Real World Haskell” and you’ll think it an anomaly, just some noise in the data.

Why learn this?

Apart from wanting to become a better programmer in general (which would explain why I’d want to learn functional programming in general and in more detail than I already do from Erlang and Clojure), I want to learn how Haskell can be a practical language - how it can help me create great products. I suspect that behind the terseness and high degree of greek characters is a toolkit that will be at least as empowering as Erlang/OTP has been. I want that toolkit.

The elephant in the room

Sooner or later you will arrive at the Haskell trial stage. In order to print anything out from your programme, or accept any input or read a file etc. you will have to use monads. At first the syntax will seem very strange, just a load of terse boilerplate for doing what more pragmatic languages make super easy, but you’ll think “whatever, let’s just get on with learning this thing”. At some point the tutorial or book you’re reading will have to explain monads to you. More than likely this is the point where you stared at the screen/page in disbelief and your heart sank as you realised you would have to understand level 3000 mathematics to print something on screen. For most people, this is the last they ever deal with Haskell.

Later on, a Haskell wizard will act all puzzled and amused that you found monads hard to understand. This will lower your self-esteem so low you consider giving up entirely and becoming a farmer instead. They will go on to tell you that you’ve been using monads the whole time in whatever programming language you like. They will explain how this is so and you will not be enlightened. It’ll sound all too convenient, just a bunch of semantic drivel.

The reason so many of us have such a frustrating initial experience with Haskell is that most of the books on the subject are appallingly badly written. Programming books are in general a complete shambles and very few are useful to anyone who isn’t already pretty hot at the whole thing anyway. If you were lucky enough to find a well-written helpful introduction to Haskell (there are some), then you might not be feeling this way. Also if you were born a Haskell wizard, this will sound like complete gobbledegook to you. But then you’re not really human now are you? Admit it.

Anyway, I will be attending the Haskell hoodlums meetup this Thursday so hopefully I’ll start understanding this thing. Don’t give up people! Good luck.

David Cameron on AV

by

David Cameron:

“I just feel it, in my gut, that AV is wrong. Politics shouldn’t be some mind-bending exercise.

British people are pretty thick. I mean, have you seen them? I seriously doubt they understand the whole “tick the party you want in government” thing - how are they going to understand they can actually vote for their views with this system. Given that we’ve slashed education funding, it’s unlikely we’re gonna end up with a whole lot of people who can understand anything about politics, which is how we like it. Nice and stupid. Means we don’t have to say anything meaningful to get them to vote for us.

“It’s about what you feel in your gut – about the values you hold dear and the beliefs you instinctively have. And I just feel it, in my gut, that AV is wrong.

Gut feeling as a way to decide who should be in power. So a knee-jerk reaction is what we’re looking for, we don’t want Brits having to look at the policies of the parties - we want them to vote tribally.

“There are three big problems with AV that strike at the heart of how I believe our democracy should work.

First, I believe power should lie with the people – and AV would take some of that power away.

I’m not going to explain why it takes power away because obviously it doesn’t. All you need to do is vote once to get the exact same vote as you would under FPTP, so the system doesn’t take any power away from the individual. But this is some scary sounding rhetoric. Hopefully people will be scared enough not to question the assertion.

“Second, I believe there should be real accountability between the pledges politicians put in their manifestos and the action they take in government.

Because this is obviously the case now. Also it’s easy for me, we didn’t put any actual pledges in the Conservative manifesto, so it looks like we’ve stuck to it pretty closely.

“AV would damage that chain of accountability. And third, I believe in the principle of one person, one vote.

I have no actual reason for saying no to AV except it would make us work harder to retain those safe seats.

“If you want a system that makes your politicians accountable.

“If you want a system that enshrines the principle of one person, one vote. “You must vote on May 5th, and you must vote No to AV. “The biggest danger right now is that Britain sleepwalks into this second-rate system, waking up on May 6th with a voting system that damages our democracy. “We must not let that happen. So we’ve got to get out there and fight, and get out there and win.”

Voting for something is like sleep-walking because all the people voting YES are all asleep. Let’s keep Britain’s electoral system thoroughly in the dark ages!