Haskell solution