This is an oxidation-reduction (redox) reaction:
4 HI + 4 e- → 4 H0 (reduction)
Mg0 - 2 e- → MgII (oxidation)
2 O-II - 2 e- → 2 O-I (oxidation)
H2O is an oxidizing agent, Mg is a reducing agent, H2O is a reducing agent.
Reactants:
Products: