20100112

using the parseargs package

This week I found the parseargs package in Hackage to be useful. It makes handling command-line arguments for your program easy, and gives the user a very pleasant command-line interface to your program.
However, I also needed to use the command line options for the GHC runtime system in my compiled program.
The important thing to note (which I missed on a first sleepy reading) is this:

When your Haskell program starts up, its RTS extracts command-line arguments bracketed between +RTS and -RTS as its own. For example:

% ./a.out -f +RTS -p -S -RTS -h foo bar 

The RTS will snaffle -p -S for itself, and the remaining arguments -f -h foo bar will be handed to your program if/when it calls System.getArgs.

If you do that, then you can use the command line arguments for the RTS along with whatever you have written into your program.

20100105

profiling your Haskell program: enable profiling for libraries

Having read this chapter in Real World Haskell, I wanted to profile the program I'm working on.
http://book.realworldhaskell.org/read/profiling-and-optimization.html
Unfortunately, right away I got errors because profiling hadn't been enabled for the modules I was importing. The Haskell wiki has this page:
http://www.haskell.org/haskellwiki/How_to_profile_a_Haskell_program
The process described there for enabling profiling in libraries is fine if you just need one library, but as it turned out, I needed to enable profiling in about six libraries. What a pain!

In the section called 2.2 Enable profiling on libraries, this information should absolutely be included, particularly the answer:
http://stackoverflow.com/questions/1704421/cabal-not-installing-dependencies-when-needing-profiling-libraries
You just need to do this:
vim ~/.cabal/config
Uncomment this line and set it to True:
library-profiling: True
After that, you need to cabal install __(module)__ --reinstall for each module you are using, and their dependencies as well. Unfortunately, cabal isn't smart enough to do it all the way down automatically yet.

That is so much easier than doing each library by hand, though. I was about to get really frustrated until I read that post on StackOverflow.