Reorganisation of the source tree
[ghc-hetmet.git] / compiler / basicTypes / FieldLabel.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1996-1998
3 %
4 \section[FieldLabel]{The @FieldLabel@ type}
5
6 \begin{code}
7 module FieldLabel(
8         FieldLabel,     -- Abstract
9
10         mkFieldLabel, 
11         fieldLabelName, fieldLabelTyCon, fieldLabelType, fieldLabelTag,
12
13         FieldLabelTag,
14         firstFieldLabelTag, allFieldLabelTags
15   ) where
16
17 #include "HsVersions.h"
18
19 import Type( Type )
20 import TyCon( TyCon )
21 import Name             ( Name{-instance Eq/Outputable-}, NamedThing(..), nameUnique )
22 import Outputable
23 import Unique           ( Uniquable(..) )
24 \end{code}
25
26 \begin{code}
27 data FieldLabel
28   = FieldLabel  Name            -- Also used as the Name of the field selector Id
29
30                 TyCon           -- Parent type constructor
31
32                 Type            -- Type of the field; may have free type variables that
33                                 -- are the tyvars of its parent *data* constructor, and
34                                 -- those will be the same as the tyvars of its parent *type* constructor
35                                 -- e.g.  data T a = MkT { op1 :: a -> a, op2 :: a -> Int }
36                                 -- The type in the FieldLabel for op1 will be simply (a->a).
37
38                 FieldLabelTag   -- Indicates position within constructor
39                                 -- (starting with firstFieldLabelTag)
40                                 --
41                                 -- If the same field occurs in more than one constructor
42                                 -- then it'll have a separate FieldLabel on each occasion,
43                                 -- but with a single name (and presumably the same type!)
44
45 type FieldLabelTag = Int
46
47 mkFieldLabel = FieldLabel
48
49 firstFieldLabelTag :: FieldLabelTag
50 firstFieldLabelTag = 1
51
52 allFieldLabelTags :: [FieldLabelTag]
53 allFieldLabelTags = [firstFieldLabelTag..]
54
55 fieldLabelName  (FieldLabel n _ _  _)   = n
56 fieldLabelTyCon (FieldLabel _ tc _ _)   = tc
57 fieldLabelType  (FieldLabel _ _ ty _)   = ty
58 fieldLabelTag   (FieldLabel _ _ _  tag) = tag
59
60 instance Eq FieldLabel where
61     fl1 == fl2 = fieldLabelName fl1 == fieldLabelName fl2
62
63 instance Outputable FieldLabel where
64     ppr fl = ppr (fieldLabelName fl)
65
66 instance NamedThing FieldLabel where
67     getName = fieldLabelName
68
69 instance Uniquable FieldLabel where
70     getUnique fl = nameUnique (fieldLabelName fl)
71 \end{code}