ee8fb1cb6f245ab46be781d9da8d7b05d287bd40
[ghc.git] / testsuite / tests / typecheck / should_compile / tc222.hs
1 {-# LANGUAGE ImplicitParams, RankNTypes #-}
2
3 -- Tests impredivative polymorphism with left-to-right
4 -- flow information; see the uses of "$"
5
6 module TestIP where
7
8 import Control.Monad.ST
9 import Data.STRef
10
11 -- Here's a use of runST with ($)
12 foo = runST $ (do { v <- newSTRef 0; readSTRef v })
13
14 -- Here's a use of implicit parameters with ($)
15
16 type PPDoc = (?env :: Int) => Char -> Char
17
18 f :: PPDoc -> PPDoc
19 f c = g $ c
20
21 -- Fully annotated version of f, as compiled by GHC 6.4.2
22 --
23 -- f ?env c = $ (C->C) (C->C)
24 -- (\(x:C->C). g ?env (\?env. x))
25 -- (c ?env)
26 --
27 -- The subsumption test needed from the call to $ is this:
28 -- ?env => (?env => C -> C) -> C -> C <= a->b
29 -- (?env => C -> C) -> C -> C <= a->b
30 -- (a) C->C <= b
31 -- (b) a <= (?env => C -> C)
32 -- And perhaps surprisingly (b) succeeds!
33
34 g :: PPDoc -> PPDoc
35 g d = d
36
37
38