Haskell code for general purposes