gitlab-ci: Move hadrian-ghc-in-ghci job first
[ghc.git] / testsuite / tests / typecheck / should_compile / Vta1.hs
1 {-# LANGUAGE TypeApplications, ScopedTypeVariables, PolyKinds,
2 TypeFamilies, RankNTypes,
3 FlexibleContexts #-}
4 -- tests about visible type application
5
6 module Vta1 where
7
8 import Data.Kind (Type)
9
10 quad :: a -> b -> c -> d -> (a, b, c, d)
11 quad = (,,,)
12
13 silly = quad @_ @Bool @Char @_ 5 True 'a' "Hello"
14
15 pairup_nosig x y = (x, y)
16
17 pairup_sig :: a -> b -> (a,b)
18 pairup_sig u w = (u, w)
19
20 answer_sig = pairup_sig @Bool @Int False 7 --
21 -- (False, 7) :: (Bool, Int)
22
23 answer_read = show (read @Int "3") -- "3" :: String
24 answer_show = show @Integer (read "5") -- "5" :: String
25 answer_showread = show @Int (read @Int "7") -- "7" :: String
26
27 intcons a = (:) @Int a
28
29 intpair x y = pairup_sig @Int x y
30
31 answer_pairup = pairup_sig @Int 5 True -- (5, True) :: (Int, Bool)
32 answer_intpair = intpair 1 "hello" -- (1, "hello") :: (Int, String)
33 answer_intcons = intcons 7 [] -- [7] :: [Int]
34
35 type family F a
36 type instance F Char = Bool
37
38 g :: F a -> a
39 g _ = undefined
40
41 f :: Char
42 f = g True
43
44 answer = g @Char False
45
46 mapSame :: forall b. (forall a. a -> a) -> [b] -> [b]
47 mapSame _ [] = []
48 mapSame fun (x:xs) = fun @b x : (mapSame @b fun xs)
49
50 pair :: forall a. a-> (forall b. b -> (a, b))
51 pair x y = (x, y)
52
53 b = pair @Int 3 @Bool True
54 c = mapSame id [1,2,3]
55 d = pair 3 @Bool True
56
57 pairnum :: forall a. Num a => forall b. b -> (a, b)
58 pairnum = pair 3
59
60 e = (pair 3 :: forall a. Num a => forall b. b -> (a, b)) @Int @Bool True
61 h = pairnum @Int @Bool True
62
63 data First (a :: Type -> Type) = F
64 data Proxy (a :: k) = P -- This expands to P (kind variable) (type variable)
65 data Three (a :: Type -> k -> Type) = T
66
67 foo :: Proxy a -> Int
68 foo _ = 0
69
70 first :: First a -> Int
71 first _ = 0
72
73 fTest = first F
74 fMaybe = first @Maybe F
75
76 test = foo P
77 bar = foo @Bool P -- should work
78
79 too :: Three a -> Int
80 too _ = 3
81
82 threeBase = too T
83 threeOk = too @Either T
84
85 blah = Nothing @Int
86
87 newtype N = MkN { unMkN :: forall a. Show a => a -> String }
88
89 n = MkN show
90
91 boo = unMkN n @Bool
92
93 boo2 :: forall (a :: Type -> Type) . Proxy a -> Bool
94 boo2 _ = False
95
96 base = boo2 P
97 bar'= boo2 @Maybe P -- should work