2 % (c) The AQUA Project, Glasgow University, 1996-1998
4 \section[FieldLabel]{The @FieldLabel@ type}
7 module FieldLabel where
9 #include "HsVersions.h"
11 import {-# SOURCE #-} TypeRep( Type ) -- FieldLabel is compiled very early
13 import Name ( Name{-instance Eq/Outputable-}, NamedThing(..), nameUnique )
15 import Unique ( Uniquable(..) )
20 = FieldLabel Name -- Also used as the Name of the field selector Id
21 Type -- Type of the field; may have free type variables that
22 -- are the tyvars of its parent *data* constructor, and
23 -- those will be the same as the tyvars of its parent *type* constructor
24 -- e.g. data T a = MkT { op1 :: a -> a, op2 :: a -> Int }
25 -- The type in the FieldLabel for op1 will be simply (a->a).
27 FieldLabelTag -- Indicates position within constructor
28 -- (starting with firstFieldLabelTag)
30 -- If the same field occurs in more than one constructor
31 -- then it'll have a separate FieldLabel on each occasion,
32 -- but with a single name (and presumably the same type!)
34 type FieldLabelTag = Int
36 mkFieldLabel = FieldLabel
38 firstFieldLabelTag :: FieldLabelTag
39 firstFieldLabelTag = 1
41 allFieldLabelTags :: [FieldLabelTag]
42 allFieldLabelTags = [firstFieldLabelTag..]
44 fieldLabelName (FieldLabel n _ _) = n
45 fieldLabelType (FieldLabel _ ty _) = ty
46 fieldLabelTag (FieldLabel _ _ tag) = tag
48 instance Eq FieldLabel where
49 (FieldLabel n1 _ _) == (FieldLabel n2 _ _) = n1 == n2
51 instance Outputable FieldLabel where
52 ppr (FieldLabel n _ _) = ppr n
54 instance NamedThing FieldLabel where
55 getName (FieldLabel n _ _) = n
57 instance Uniquable FieldLabel where
58 getUnique (FieldLabel n _ _) = nameUnique n