average (float array[], int length)
{
  return avg (array[], length, i, 0, 0, 0), { i = 0 };
}

avg average (float array[], int length, int index, int weight, int divider, float64 total)
{
  return avg (array[], length, (index + 1), next_weight, next_divider, next_total),
  {
    next_divider = divider + (weight + 1),
    {    
      next_weight = weight + 1,
      {
        next_total = total + x * (weight + 1),
        {
          x = array[index]
        }
      }
    }
  };
}

avg average (float array[], int length, int index, int weight, int divider, float64 total)
         if (index == length)
{
  if (divider) return total / divider;
  else return 0;
}