Embrace -XTypeInType, add -XStarIsType
[ghc.git] / testsuite / tests / typecheck / should_compile / T12133.hs
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE ConstraintKinds #-}
3 {-# LANGUAGE GADTs #-}
4 {-# LANGUAGE ImplicitParams #-}
5 {-# LANGUAGE KindSignatures #-}
6 {-# LANGUAGE MagicHash #-}
7 {-# LANGUAGE RankNTypes #-}
8 {-# LANGUAGE ScopedTypeVariables #-}
9 {-# LANGUAGE TypeOperators #-}
10
11 module T12133 where
12
13 import GHC.Classes (IP(..))
14 import Data.Kind (Constraint, Type)
15
16 -- | From "Data.Constraint":
17 data Dict :: Constraint -> Type where Dict :: a => Dict a
18
19 newtype a :- b = Sub (a => Dict b)
20
21 infixl 1 \\ -- required comment
22
23 (\\) :: a => (b => r) -> (a :- b) -> r
24 r \\ Sub Dict = r
25
26 -- | GHC 7.10.2 type checks this function but GHC 8.0.1 does not unless
27 -- you modify this example in one of the following ways:
28 --
29 -- * uncomments the type signature for 'Sub'
30 --
31 -- * flatten the nested pairs of constraints into a triple of constraints
32 --
33 -- * replace 'IP sym ty' with 'c9', where 'c9' is a new constraint variable.
34 --
35 -- The error message is listed below.
36 foo :: forall c1 c2 c3 sym ty
37 . (c1, c2) :- c3
38 -> (c1, (IP sym ty, c2)) :- (IP sym ty, c3)
39 foo sp = ( Sub
40 -- :: ((c1, (IP sym ty, c2)) => Dict (IP sym ty, c3))
41 -- -> (c1, ((IP sym ty), c2)) :- (IP sym ty, c3)
42 )
43 ( (Dict \\ sp) :: Dict (IP sym ty, c3) )
44
45 {- Compiler error message:
46
47 GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
48 [1 of 1] Compiling T ( t.hs, interpreted )
49
50 t.hs:44:13: error:
51 • Could not deduce: IP sym ty arising from a use of ‘Dict’
52 from the context: (c1, (IP sym ty, c2))
53 bound by a type expected by the context:
54 (c1, (IP sym ty, c2)) => Dict (IP sym ty, c3)
55 at t.hs:(40,10)-(44,49)
56 or from: c3
57 bound by a type expected by the context:
58 c3 => Dict (IP sym ty, c3)
59 at t.hs:44:13-22
60 • In the first argument of ‘(\\)’, namely ‘Dict’
61 In the first argument of ‘Sub’, namely
62 ‘((Dict \\ sp) :: Dict (IP sym ty, c3))’
63 In the expression: (Sub) ((Dict \\ sp) :: Dict (IP sym ty, c3))
64 • Relevant bindings include
65 foo :: (c1, c2) :- c3 -> (c1, (IP sym ty, c2)) :- (IP sym ty, c3)
66 (bound at t.hs:40:1)
67 Failed, modules loaded: none.
68 -}