very verbose answer to prob 47 in haskell..