[Haskell-beginners] programming with Error monad
Dennis Raddle
dennis.raddle at gmail.com
Sat Sep 1 21:59:19 CEST 2012
I recently completed a large project and started another one. The first
project was about processing music, in particular taking MusicXML and/or
Sibelius files (Sibelius is a music notation program) and producing MIDI
files according to the specifications I wanted.
The second project is about algorithmic music composition.
To handle errors in the first project, I used "throw" to throw exceptions.
Now I am using the Error monad... actually a combination of ErrorT and
State. (In the state I hold a random generator for use in algorithms that
require pseudo-randomness.)
I notice two things now. The first thing is that I can catch and rethrow
errors to provide annotation about the context. It's like getting a stack
trace automatically every time there is an error. I realize now this makes
it easier to debug, and during my first project I spent a lot of time
debugging that might have been avoidable. (I confess I never could figure
out the ghci debugger, which might have helped.)
The second thing is that there seems to be less laziness. Every statement
in a do statement seems to execute even if I don't use result. I think. I
would have to do some more experiments, but that is what it looks like
right now. That is another good thing for debugging... less laziness (and
maybe guaranteed order of execution too?) means it's easier to understand
what the program is attempting to do.
Does this seem correct?
Dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120901/cc2dac98/attachment.htm>
More information about the Beginners
mailing list