changed Ruby script into Haskell