Testsuite error message changes
[ghc.git] / testsuite / tests / typecheck / should_run / tcrun036.hs
1 {-# LANGUAGE Rank2Types #-}
2
3 -- Another test for the new feature that contexts in a mutually
4 -- recursive group do not need to be of the same length
5 -- I'm putting it here mainly to document the need
6
7 -- GHC used to say:
8 --
9 -- Bug.lhs:23:10:
10 -- Inferred type is less polymorphic than expected
11 -- Quantified type variable `c' is mentioned in the environment:
12 -- printCatalog :: c -> IO () (bound at Bug.lhs:28:0)
13 -- In the `viewCatalog' field of a record
14
15 -- Bug.lhs:27:0:
16 -- Contexts differ in length
17 -- When matching the contexts of the signatures for
18 -- printer :: Viewer
19 -- printCatalog :: forall c. (Catalog c) => View c
20 -- The signature contexts in a mutually recursive group should all be identical
21
22 module Main where
23
24 import Prelude hiding (traverse)
25
26 class Catalog c where
27 mtraverse :: c -> Viewer -> IO ()
28
29 instance Catalog Int where
30 mtraverse i v = viewShowable v i
31
32 type View a = a -> IO ()
33
34 data Viewer = Viewer {
35 viewShowable :: forall s. Show s => View s,
36 viewCatalog :: forall c. Catalog c => View c
37 }
38
39 printer :: Viewer
40 --printer = Viewer {
41 -- viewCatalog = \x -> mtraverse x printer,
42 -- viewShowable = putStrLn . show }
43 printer = Viewer {
44 viewCatalog = printCatalog,
45 viewShowable = putStrLn . show }
46
47 printCatalog :: forall c. Catalog c => View c
48 printCatalog x = mtraverse x printer
49
50 data X = X {
51 cat :: Int
52 }
53
54 instance Catalog X where
55 mtraverse x v = do
56 viewCatalog v (cat x)
57
58 main = do
59 let x = X { cat = 20 }
60 mtraverse x printer