A not-half-bad haskell solution