summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile/tc222.hs
blob: 4c5717e50a9e0462a76cf85944740b1ad9ac9b2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE ImplicitParams, RankNTypes #-}

-- Tests impredivative polymorphism with left-to-right
-- flow information; see the uses of "$"

module TestIP where

import Control.Monad.ST
import Data.STRef

-- Here's a use of runST with ($)
foo = runST $ (do { v <- newSTRef 0; readSTRef v })

-- Here's a use of implicit parameters with ($)

type PPDoc = (?env :: Int) => Char -> Char

f :: PPDoc -> PPDoc
f c = g $ c

-- Fully annotated version of f, as compiled by GHC 6.4.2
--
-- f ?env c = $ (C->C) (C->C)
--              (\(x:C->C). g ?env (\?env. x))
--              (c ?env)
--
-- The subsumption test needed from the call to $ is this:
--      ?env => (?env => C -> C) -> C -> C   <=  a->b
--      (?env => C -> C) -> C -> C   <=  a->b
--      (a) C->C <= b
--      (b) a <= (?env => C -> C)
-- And perhaps surprisingly (b) succeeds!

g :: PPDoc -> PPDoc
g d = d