added better haskell solution