There is a library for Haskell that will do it. Though it doesn't support all GHC versions. It's very nifty if you need it.
https://github.com/jberthold/packman