[project @ 1998-11-16 18:14:44 by simonm]
[ghc-hetmet.git] / ghc / tests / typecheck / should_compile / tc087.hs
1 module ShouldSucceed where
2
3 data SeqView t a              =  Null
4                               |  Cons a (t a)
5
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
13
14 toOrderedList q         =  case splitMin q of
15    Null                 -> []
16    Cons a q             -> a : toOrderedList q
17
18 insertMany x q          =  foldr insert q x
19 pqSort q x              =  toOrderedList (insertMany x q)
20
21 check                   :: forall q. (PriorityQueue q) => (forall a. Ord a => q a) -> IO ()
22 check empty             =  do
23     putStr "*** sorting\n"
24     out (pqSort empty [1 .. 99])
25     out (pqSort empty [1.0, 1.1 ..99.9])
26
27 out                             :: (Num a) => [a] -> IO ()
28 out x | sum x == 0              =  putStr "ok\n"
29       | otherwise               =  putStr "ok\n"
30