Do problem 27 in Haskell.