Solve #39 in Haskell.