summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile/TcCoercibleCompile.hs
blob: 49ad7bb5b295123c0177539216278e8fdf3fb3e0 (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
39
40
41
42
43
44
45
46
47
48
49
50
{-# LANGUAGE RoleAnnotations #-}
{-# OPTIONS_GHC -fwarn-unused-imports  #-}

import Data.Coerce
import Data.Proxy
import Data.Monoid (First(First)) -- check whether the implicit use of First is noted

-- see https://gitlab.haskell.org/ghc/ghc/wikis/design/new-coercible-solver/v2

foo1 :: f a -> f a
foo1 = coerce

newtype X = MkX (Int -> X)
foo2 :: X -> X
foo2 = coerce

newtype X2 a = MkX2 Char
type role X2 nominal

foo3 :: X2 Int -> X2 Bool
foo3 = coerce

newtype Age = MkAge Int
newtype Y a = MkY a
type role Y nominal

foo4 :: Y Age -> Y Int
foo4 = coerce

newtype Z a = MkZ ()
type role Z representational

foo5 :: Z Int -> Z Bool
foo5 = coerce

newtype App f a = MkApp (f a)

foo6 :: f a -> App f a
foo6 = coerce

foo7 :: Coercible a b => b -> a
foo7 = coerce

foo8 :: (Coercible a b, Coercible b c) => Proxy b -> a -> c
foo8 _ = coerce

main = print (coerce $ Just (1::Int)  :: First Int)