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