Completed Haskell implementation