AlgebraicStructures code factored out as a trait