Generalized saveGameState into writeIORefF and writeIORefF' which are varients of writeIORef lifted into Foldable