2 % (c) The AQUA Project, Glasgow University, 1996-1998
4 \section[FieldLabel]{The @FieldLabel@ type}
8 FieldLabel, -- Abstract
11 fieldLabelName, fieldLabelTyCon, fieldLabelType, fieldLabelTag,
14 firstFieldLabelTag, allFieldLabelTags
17 #include "HsVersions.h"
21 import Name ( Name{-instance Eq/Outputable-}, NamedThing(..), nameUnique )
23 import Unique ( Uniquable(..) )
28 = FieldLabel Name -- Also used as the Name of the field selector Id
30 TyCon -- Parent type constructor
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).
38 FieldLabelTag -- Indicates position within constructor
39 -- (starting with firstFieldLabelTag)
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!)
45 type FieldLabelTag = Int
47 mkFieldLabel = FieldLabel
49 firstFieldLabelTag :: FieldLabelTag
50 firstFieldLabelTag = 1
52 allFieldLabelTags :: [FieldLabelTag]
53 allFieldLabelTags = [firstFieldLabelTag..]
55 fieldLabelName (FieldLabel n _ _ _) = n
56 fieldLabelTyCon (FieldLabel _ tc _ _) = tc
57 fieldLabelType (FieldLabel _ _ ty _) = ty
58 fieldLabelTag (FieldLabel _ _ _ tag) = tag
60 instance Eq FieldLabel where
61 fl1 == fl2 = fieldLabelName fl1 == fieldLabelName fl2
63 instance Outputable FieldLabel where
64 ppr fl = ppr (fieldLabelName fl)
66 instance NamedThing FieldLabel where
67 getName = fieldLabelName
69 instance Uniquable FieldLabel where
70 getUnique fl = nameUnique (fieldLabelName fl)