Solution to 9 in Haskell.