implementation of lastdig in haskell