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"
19 import {-# SOURCE #-} TypeRep( Type ) -- FieldLabel is compiled very early
20 import {-# SOURCE #-} TyCon( TyCon ) -- FieldLabel is compiled very early
22 import Name ( Name{-instance Eq/Outputable-}, NamedThing(..), nameUnique )
24 import Unique ( Uniquable(..) )
29 = FieldLabel Name -- Also used as the Name of the field selector Id
31 TyCon -- Parent type constructor
33 Type -- Type of the field; may have free type variables that
34 -- are the tyvars of its parent *data* constructor, and
35 -- those will be the same as the tyvars of its parent *type* constructor
36 -- e.g. data T a = MkT { op1 :: a -> a, op2 :: a -> Int }
37 -- The type in the FieldLabel for op1 will be simply (a->a).
39 FieldLabelTag -- Indicates position within constructor
40 -- (starting with firstFieldLabelTag)
42 -- If the same field occurs in more than one constructor
43 -- then it'll have a separate FieldLabel on each occasion,
44 -- but with a single name (and presumably the same type!)
46 type FieldLabelTag = Int
48 mkFieldLabel = FieldLabel
50 firstFieldLabelTag :: FieldLabelTag
51 firstFieldLabelTag = 1
53 allFieldLabelTags :: [FieldLabelTag]
54 allFieldLabelTags = [firstFieldLabelTag..]
56 fieldLabelName (FieldLabel n _ _ _) = n
57 fieldLabelTyCon (FieldLabel _ tc _ _) = tc
58 fieldLabelType (FieldLabel _ _ ty _) = ty
59 fieldLabelTag (FieldLabel _ _ _ tag) = tag
61 instance Eq FieldLabel where
62 fl1 == fl2 = fieldLabelName fl1 == fieldLabelName fl2
64 instance Outputable FieldLabel where
65 ppr fl = ppr (fieldLabelName fl)
67 instance NamedThing FieldLabel where
68 getName = fieldLabelName
70 instance Uniquable FieldLabel where
71 getUnique fl = nameUnique (fieldLabelName fl)