pure functional implementation of leftist heap