learn haskell and refactor to fix a bug