haskell implementation