Purely Functional Heap Sort in Scala

Inspired by the blog post Purely functional Heap Sort in OCaml, F# and Haskell on The Flying Frog Blog I decided to implement the same datastructure and operations in Scala to get one little step closer to Scala mastery. This code is not idiomatic Scala, but I think it is decent anyway. If you have any comments, feel free to contact me as usual.

Challenge: Rewrite the code to be more object-oriented. (Disclaimer: I don’t think it’s possible to write toList as a method and have the tail recursion optimization kick in, but I’d love to be proven wrong.)

Don’t forget to take a look at the OCaml, F# and Haskell versions and compare. Note the amount of types that Scala can’t infer.

Update: The code has been updated with some improvements suggested by Robbert.