Solve #47 in Haskell.