Add GHCi help message for :def! and :: commands
[ghc.git] / testsuite / tests / typecheck / should_compile / tc163.hs
1 {-# LANGUAGE RankNTypes #-}
2
3 -- This one killed GHC 5.05 and earlier
4 -- The problem was in a newtype with a record selector, with
5 -- a polymorphic argument type. MkId generated a bogus selector
6 -- function
7
8 module ShouldCompile where
9
10 type M3 a = forall r. (forall b. M3' b -> (b -> M3' a) -> r) -> r
11
12 newtype M3' a = M3' { mkM3' :: M3 a }
13
14 flop :: forall a b. M3' b -> (b -> M3' a) -> Int
15 flop = \m' k -> mkM3' m' (\bm k1 -> error "urk")
16
17 -- Suppose mkM3' has the straightforward type:
18 -- mkM3' :: forall a. M3' a -> M3 a
19 -- Then (mkM3' m') :: forall r. (forall b. ...) -> r
20 -- If we simply do a subsumption check of this against
21 -- alpha -> Int
22 -- where alpha is the type inferred for (\bm k1 ...)
23 -- this won't work.
24
25 -- But if we give mkM3' the type
26 -- forall a r. M3' a -> (forall b. ...) -> r
27 -- everthing works fine. Very very delicate.
28
29 ---------------- A more complex case -------------
30 bind :: M3 a -> (a -> M3 b) -> M3 b
31 bind m k b = b (M3' m) (\a -> M3' (k a))
32
33 observe :: M3 a -> a
34 observe m
35 = m (\m' k -> mkM3' m'
36 (\bm k1 -> observe (bind (mkM3' bm)
37 (\a -> bind (mkM3' (k1 a)) (\a -> mkM3' (k a)))))
38 )
39