heapsort and metafunctional programming