Wednesday, March 9, 2011

Debuggable functions in Haskell

Long long time ago, when I was writing my first Haskell apps I had this huge problem - debugging. Because for majority of my life I was debugging more or less by writing printf(some variables) I was trying to apply this same pattern to Haskell. Unfortunately it didn't work. Didn't work because functions in Haskell do not allowed side effects, so if you don't want to (don't know how) use monads it isn't simple task to do, to write something to a screen, when you are in a function. In a last few years at least 10 people asked me how to write some debugging information on the screen, to try to figure out what is going on in your code, when it does not work, so far I was unable to point a good article how to do it, and I had to explain everything by myself. When you drink a beer with your mate and you try to explain how to use monads on a piece of tissue, it is not a good way, how to teach people anything. So I was so happy to find recently this article. It explains the problem (why it is not easy to write something on a screen when you are in a function) and how to deal with it so you don't need to refactor your code dramatically. Excellent work Darius, keep it up!

No comments: