Trace of square matrices

Set

 context $n\in \mathbb N$ context $M$ … abelian monoid
 definiendum $\mathrm{tr}:\mathrm{SquareMatrix}(n,M)\to M$ definiendum $\mathrm{tr}(A):=\sum_{k=1}^n A_{kk}$