Haskell, day one

On to the final language featured in the book, Haskell. I first came across Haskell in a fantastic course in college that was all about different programming paradigms as well as the history and evolution of programming languages. In addition to learning about a whole bunch of different languages, programming exercises in the course were in Haskell. I remember being blown away by pattern matching (e.g in defining functions) and destructuring in Haskell, but unfortunately can't remember too much else. It was a really informative class for me as it opened my eyes to different ways programming could 'be', at the time i was pretty much jest learning to code and had only been exposed to C++, so my impression of all programming was that it was somewhat like C++. Taking this course and programming in Haskell was informative in broadening my perspective (though the class was a bit over my head at times—I don't even think i had taken data structures by the time i took this class and i remember a lecture on implementing a basic lisp interpreter in lisp that left me swimming for a bit); and leaving me with an appreciation of how different languages approach modelling computation. In many ways this book is like that class!

Anyway onto the text, day one was relatively straightforward (and a lot of my solutions built off of stuff remembered from prolog). Getting an environment setup and kicking the tires with expressions, function definitions and list processing. I don't have much to add to the code itself, which i will post below. It was interesting trying to solve the map coloring problem, who'da thunk list comprehensions would be so useful.

Another thing I noted is that I wrote very few type annotations, now this really was a small collection of small independent functions so that isn't saying much yet, but the type inference is nice, and Haskell is reputed to have quite a powerful type inference system. It will be interesting to see how this works out as I know the type system is a major aspect of Haskell.

Posted On 31st January 2012

comments powered by Disqus