I have a data type that goes:
BinHeap a = [BinTree a]
BinTree a = Node a i (BinHeap a)
I want a function to go through a Bintree a and give me the smallest a.
extractMin :: BinHeap a -> a
extractMin ps
= foldl1 (\(Node x y z) (Node x' y' z') -> Node (smaller x x') y z) ps
where
smaller x y = if x <= y then x else y
And it crashed. And i do not know why. Because the function within fold1 outputs a BinTree, therefore it should not crash.
Thank you for your time