Implementation of heaps (3rd chapter of Okasaki)