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