Haskell implementation.