summaryrefslogtreecommitdiff
path: root/testsuite/tests/overloadedrecflds/should_run/hasfieldrun01.hs
blob: eb301baf179d14b644b2c3c8f56070dca93ead1f (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
51
{-# LANGUAGE DataKinds
           , DatatypeContexts
           , FlexibleInstances
           , GADTs
           , MultiParamTypeClasses
           , TypeFamilies
           , TypeApplications
  #-}

import GHC.Records (HasField(..))

type family B where B = Bool

data T = MkT { foo :: Int, bar :: B }

data U a b = MkU { baf :: a }

data family V a b c d
data instance V x Int y [z] = MkVInt { baz :: (x, y, z, Bool) }

data W a where
  MkW :: { woo :: a } -> W [a]

data Eq a => X a = MkX { xoo :: a }
data Y a = Eq a => MkY { yoo :: a }

t = MkT 42 True

u :: U Char Char
u = MkU 'x'

v = MkVInt (42, 'x', True, False)

w = MkW True

x = MkX True

y = MkY True

-- A virtual foo field for U
instance HasField "foo" (U a b) [Char] where
  getField _ = "virtual"

main = do print (getField @"foo" t)
          print (getField @"bar" t)
          print (getField @"baf" u)
          print (getField @"foo" u)
          print (getField @"baz" v)
          print (getField @"woo" w)
          print (getField @"xoo" x)
          print (getField @"yoo" y)