[Haskell] optimisation of State monad