[L03] State monad instance and helper functions (to Ex 7)