One of my personal goals for 2010 was to learn a new programming language, something quite different from my favourite language, Python.
After researching a number of alternatives I decided on Haskell, as I’ve never had exposure to functional languages. From the Haskell Wiki:
“Haskell is a computer programming language. In particular, it is a polymorphically statically typed, lazy, purely functional language, quite different from most other programming languages. The language is named for Haskell Brooks Curry, whose work in mathematical logic serves as a foundation for functional languages. Haskell is based on the lambda calculus, hence the lambda we use as a logo.”
I won’t go into the details of the above; those who care will know about it already, and for the rest, this post won’t be that relevant :-)
I learn best when I have a practical problem to program against, so I chose to implement a program involving data transformation. Every quarter at Steadyhand we receive a CSV file with the positions of the securities held in our funds, which we use to calculate the asset allocation of the funds (i.e. how much is in Fixed Income, Canadian Equity, etc.). We do this by taking the CSV file and manually massaging the data in Excel into four different spreadsheets; VB macros are run to generate properly formatted data files, and then we load the data into our wealth management platform so that the information is available on client statements. It doesn’t take a lot of time (approx 2/hrs per quarter), but it is a minor annoyance and there are many business rules to remember as we convert the data, so it would be nice to automate it.
This may not be the best program to fully utilize the capabilities Haskell, but it will at least do something useful for me as I learn.
After some research, I ended up using the following resources to learn:
I then dove right in started coding, and am now about 90% complete on the project.
My observations are (in particular no order):
- the functional programming paradigm really is different (duh), and it took me quite a while to wrap my head around it. The examples in the book(s) all make sense, but when it came time to solving issues in my program, the going was very slow.
- the strong typing in Haskell drove me nuts at first, and I spent a lot of time with type errors... the various websites told me to expect this, but it was still very frustrating.
- I had small glimpses of the power and beauty of the language; there are some parts of the code that really are elegant (although I’m sure a true Haskeller would do them much better)
- OK, I’ll admit it, I still don’t really understand monads... I have to go back and read the tutorials and walk through the code. For that matter, I’m still hazy about most of the theoretical underpinnings of the language.
- I feel like there are some approaches (like list comprehensions, lambda’s, etc.) that I understand much better and will now be able to utilize in Python.
- the Haskell mailing lists have a wealth of information and there is a great sense of community. Having said that, there really aren’t that many Haskell programmers in Vancouver (as far as I can tell), so I’m not sure I would want to build the business on it just yet.