Haskell implementation of some of the functions.