new haskell algorithm