polymorphic function calc_avg