Learning something new (and finding the time)

If I really want to do it, I need to stop saying I want to do it and just do it.

A few weeks ago I went to ‘That Conference’ in the Wisconsin Dells. While I was there, something important happened: I went to an open space about functional programming, and I decided that I wanted to learn a functional language. Great, right? Well, maybe. The problem I had was that I said that I want to learn one, which is easy. I can say that I want to become an astronaut too, but that doesn’t mean that I’m doing anything to move towards the goal post that I’ve set for myself. If I really want to do it, I need to stop saying I want to do it and just do it.

Because of that I talked to a few people about functional languages, the key differences between them, and before long I had made my selection: Haskell. At that point, I stopped saying “I want to learn a functional language”, and started saying “I will learn Haskell.” Once I made that leap, finding the time was easy. I had an 8-hour car-ride home that I only had to drive a few hours of. Another half hour here while my wife goes into a shoe store, and 15 minutes there while on an unimportant conference call. Time was just coming out of the woodwork!

Getting started was really easy. I went here: http://learnyouahaskell.com/ and I started going through the book.

Once you get past the install and Hello World, you get into arrays and functions. I had a great time with it, naming my first function “aggregate”; it took a list and a number, and recursively called itself, taking the next item off of the list and adding it to the number. Then I made another function that took just a list, and called the first function with the list and 0. A few minutes later I found out that Haskell has a sum function which does exactly that. Turns out it also runs much faster than my own function, oh well!

A bit later, I started seeing strange things happen. Things wouldn’t compile when I think they should, and column numbers would be off by a bit. Little things like that. At first I just assumed I had no idea what I was doing, but realized that I could type out exactly what the example had written, and have the compilation fail. But if I copied it, it would work. When that happened, it clicked: tabs were the culprit! I was using Notepad++, which by default aligns tabs to 4-character wide columns. Haskell however was assuming that a tab meant eight spaces, so certain whitespace-sensitive things weren’t being parsed correctly. The solution was to tell Notepad++ to just insert spaces instead of tabs (or to set tabs to equal 8 spaces, if you don’t mind tabs actually being 8 spaces).

Next up are all the different list functions, and then something called list comprehension. To me it seems a lot like LINQ, but a lot less wordy. I didn’t get a chance to dive deeply into this yet, but it really got me thinking more “functionally” as I played with it.

Now the question I get asked the most is: as a primarily C# developer, why did I choose Haskell over F#? The answer is simple enough; it’s because I wanted to move away from Microsoft and into something completely new and out of my comfort zone. I think Visual Studio is a great tool, and after not using it for a short while I have learned to appreciate it even more.

So what did I learn, aside from Haskell? I learned that whatever it is that you want to learn or do, you have enough time. Go do it!

Leave a Reply

Your email address will not be published. Required fields are marked *