2 % (c) The AQUA Project, Glasgow University, 1996
4 \section[FieldLabel]{The @FieldLabel@ type}
7 module FieldLabel where
9 #include "HsVersions.h"
11 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 tyvar of the constructor
23 -- e.g. data T a = MkT { op1 :: a -> a, op2 :: a -> Int }
24 -- The type in the FieldLabel for op1 will be simply (a->a).
26 FieldLabelTag -- Indicates position within constructor
27 -- If the same field occurs in more than one constructor
28 -- then it'll have a separate FieldLabel on each occasion,
29 -- but with a single name (and presumably the same type!)
31 type FieldLabelTag = Int
33 mkFieldLabel = FieldLabel
35 firstFieldLabelTag :: FieldLabelTag
36 firstFieldLabelTag = 1
38 allFieldLabelTags :: [FieldLabelTag]
39 allFieldLabelTags = [1..]
41 fieldLabelName (FieldLabel n _ _) = n
42 fieldLabelType (FieldLabel _ ty _) = ty
43 fieldLabelTag (FieldLabel _ _ tag) = tag
45 instance Eq FieldLabel where
46 (FieldLabel n1 _ _) == (FieldLabel n2 _ _) = n1 == n2
48 instance Outputable FieldLabel where
49 ppr (FieldLabel n _ _) = ppr n
51 instance NamedThing FieldLabel where
52 getName (FieldLabel n _ _) = n
54 instance Uniquable FieldLabel where
55 uniqueOf (FieldLabel n _ _) = nameUnique n