Solution to 8 in Haskell.