I’m trying to use Haskells Data.Heap module, but I’m incapable of even using it with integers. The only heap I’ve been capable of using is “empty”, which does not take any arguments.
Later on I’ll figure out how to instance for my needs, but for now I’d be glad if I was even able to test it with numbers.
Usually data structure libraries in Haskell provides
fromListfunctions to convert from a list to that structure. Data.Heap is no exception. But you’ll get some crazy errors when trying to use it:This main point here is Ambiguous type. There are several types of heaps, e.g. MaxHeap and MinHeap, which cannot be inferred from just calling
fromList. You need to tell Haskell which kind of heap you’re using with a type signature:Other constructors e.g.
singleton,fromAscList, etc. operate similarly.Once you’ve constructed the heap, the rest are easy, e.g. to insert an item to a heap
To read the top of the heap
etc.