the original haskell version

I originally wrote this in Haskell as a command-line tool, but it later
turned out that it had to be used inside C++. The Haskell file is added
for completion and back-reference.