Implementation of algorithms in Haskell