5 data SeqView t a = Null
8 class PriorityQueue q where
9 empty :: (Ord a) => q a
10 single :: (Ord a) => a -> q a
11 insert :: (Ord a) => a -> q a -> q a
12 meld :: (Ord a) => q a -> q a -> q a
13 splitMin :: (Ord a) => q a -> SeqView q a
14 insert a q = single a `meld` q
16 toOrderedList q = case splitMin q of
18 Cons a q -> a : toOrderedList q
20 insertMany x q = foldr insert q x
21 pqSort q x = toOrderedList (insertMany x q)
23 check :: (PriorityQueue q) => (Ord a => q a) -> IO ()
25 putStr "*** sorting\n"
26 out (pqSort empty [1 .. 99])
27 out (pqSort empty [1.0, 1.1 ..99.9])
29 out :: (Num a) => [a] -> IO ()
30 out x | sum x == 0 = putStr "ok\n"
31 | otherwise = putStr "ok\n"