[project @ 1997-05-19 06:25:00 by sof]
[ghc-hetmet.git] / ghc / compiler / basicTypes / FieldLabel.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1996
3 %
4 \section[FieldLabel]{The @FieldLabel@ type}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module FieldLabel where
10
11 IMP_Ubiq(){-uitous-}
12
13 import Name             --( Name{-instance Eq/Outputable-}, nameUnique )
14 import Type             ( SYN_IE(Type) )
15
16 import Outputable
17 import UniqFM           ( SYN_IE(Uniquable) )
18 \end{code}
19
20 \begin{code}
21 data FieldLabel
22   = FieldLabel  Name            -- Also used as the Name of the field selector Id
23                 Type            -- Type of the field; may have free type variables that
24                                 -- are the tyvar of the constructor
25                                 -- e.g.  data T a = MkT { op1 :: a -> a, op2 :: a -> Int }
26                                 -- The type in the FieldLabel for op1 will be simply (a->a).
27
28                 FieldLabelTag   -- Indicates position within constructor
29                                 -- If the same field occurs in more than one constructor
30                                 -- then it'll have a separate FieldLabel on each occasion,
31                                 -- but with a single name (and presumably the same type!)
32
33 type FieldLabelTag = Int
34
35 mkFieldLabel = FieldLabel
36
37 firstFieldLabelTag :: FieldLabelTag
38 firstFieldLabelTag = 1
39
40 allFieldLabelTags :: [FieldLabelTag]
41 allFieldLabelTags = [1..]
42
43 fieldLabelName (FieldLabel n _  _)   = n
44 fieldLabelType (FieldLabel _ ty _)   = ty
45 fieldLabelTag  (FieldLabel _ _  tag) = tag
46
47 instance Eq FieldLabel where
48     (FieldLabel n1 _ _) == (FieldLabel n2 _ _) = n1 == n2
49
50 instance Outputable FieldLabel where
51     ppr sty (FieldLabel n _ _) = ppr sty n
52
53 instance NamedThing FieldLabel where
54     getName (FieldLabel n _ _) = n
55
56 instance Uniquable FieldLabel where
57     uniqueOf (FieldLabel n _ _) = nameUnique n
58 \end{code}