Archive for the 'Haskell' Category

Taking Another Stab At Learning Haskell…

Sunday, March 22nd, 2009

I have been trying to learn functional programming in Haskell on and off for about two years now. The functional programming approach, terminologies and Haskell’s unfamiliar syntax makes me feel like a fish out of water every time I try to learn it. What makes it especially difficult for me is that the BSCS course I took did not have a functional programming subject plus the fact that I a mostly self-taught. I first learned to program using Atari Basic and 6502 assembly language. From then I learned C, Pascal, C++, Java, PHP, Perl, Python, and a slew of other esoteric languages. I also know CLISP and ELISP so I have some familiarity with functional programming. One thing that all these languages had in common is that they are all procedural, imperative programming languages. I have been conditioned into the mindset that a computer program is a series of instructions given to a computer. Learning functional programming and, at its heart, lambda calculus throws most of what I know about programming out the window. You are forced to think differently. Programs are no longer a series of instructions. They are now special applications of fundamental and advanced mathematical concepts.

Most of the material I have been reading so far introduces concepts which are completely foreign to me using terms that I have never even heard before (”monad”, hyukhyuk!). Some materials like “Haskell Tutorial for C Programmers” attempts to map functional programming concepts in Haskell to imperative programming concepts in C. That was my last attempt to learn Haskell prior to this current one. It starts off slow but in the next chapter it gets deep all of a sudden and I felt lost and eventually gave up.

The approach taken by “Haskell Tutorial for C Programmers” is essentially the same approach that I had taken to learn all the programming languages that I know. This approach consists of three stages:

  1. Learn about all the keywords of the new language, then map them to the keywords of a language that you already know.
  2. Learn how to do all the concepts using the new language like loops, branching, function definition, etc.
  3. Finally, learn how to do advanced I/O like reading/writing files and talking to a network.

This approach has not failed me until I tried to learn functional programming using Haskell. I eventually gave up until better material was available and I had some spare time. I have been especially productive using Django and Python lately so I have been finding a bit of time and with a new book on Haskell available for free, I decided to give it another shot.

I am reading well into chapter 3 as I write this and so far, my brain is still chugging along nicely. I took a completely different approach to learning this time: Zen Mind, Beginner’s Mind. It is at the core of the teachings of Shunryu Suzuki-roshi. Basically it means emptying your mind of all preconceived notions and being free from expectations of what should and shouldn’t be. In this mental state, all you do is explore and observe.

The approach is working thus far. However it would not be possible if “Real World Haskell” itself was written in the same cut-and-dry approach like that found in most of the books on Haskell that I have read. The book takes on a very nice pace in the first 2 chapters so far. It introduces functional programming concepts using small, working, real-world examples. It exposes only as much of the language as it needs to and explains everything in detail without overwhelming you. Considering the depth of the subject, it looks like an excellent book written in a very engaging manner.

Haskell Error Handling Examples

Tuesday, February 19th, 2008

So I was wading through the posts on Proggit today and I found a short but useful post on Haskell error handling. It is quite refreshing to find some Haskell examples that is not about printing out the Fibonacci sequence or calculating the factorial for an arbitrary integer.