39daeeca830ba17853cddba3d6cecb21b78021dd
[ghc-hetmet.git] / ghc / compiler / basicTypes / BasicTypes.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1997-1998
3 %
4 \section[BasicTypes]{Miscellanous types}
5
6 This module defines a miscellaneously collection of very simple
7 types that
8
9 \begin{itemize}
10 \item have no other obvious home
11 \item don't depend on any other complicated types
12 \item are used in more than one "part" of the compiler
13 \end{itemize}
14
15 \begin{code}
16 module BasicTypes(
17         Version, Arity, 
18         Unused, unused,
19         Fixity(..), FixityDirection(..), defaultFixity,
20         NewOrData(..), 
21         RecFlag(..), isRec, isNonRec,
22         TopLevelFlag(..), isTopLevel, isNotTopLevel
23    ) where
24
25 #include "HsVersions.h"
26
27 import Outputable
28 \end{code}
29
30 %************************************************************************
31 %*                                                                      *
32 \subsection[Unused]{Unused}
33 %*                                                                      *
34 %************************************************************************
35
36 Used as a placeholder in types.
37
38 \begin{code}
39 type Unused = ()
40
41 unused :: Unused
42 unused = error "Unused is used!"
43 \end{code}
44
45
46 %************************************************************************
47 %*                                                                      *
48 \subsection[Arity]{Arity}
49 %*                                                                      *
50 %************************************************************************
51
52 \begin{code}
53 type Arity = Int
54 \end{code}
55
56
57 %************************************************************************
58 %*                                                                      *
59 \subsection[Version]{Module and identifier version numbers}
60 %*                                                                      *
61 %************************************************************************
62
63 \begin{code}
64 type Version = Int
65 \end{code}
66
67
68 %************************************************************************
69 %*                                                                      *
70 \subsection[Fixity]{Fixity info}
71 %*                                                                      *
72 %************************************************************************
73
74 \begin{code}
75 data Fixity = Fixity Int FixityDirection
76 data FixityDirection = InfixL | InfixR | InfixN 
77                      deriving(Eq)
78
79 instance Outputable Fixity where
80     ppr (Fixity prec dir) = hcat [ppr dir, space, int prec]
81
82 instance Outputable FixityDirection where
83     ppr InfixL = ptext SLIT("infixl")
84     ppr InfixR = ptext SLIT("infixr")
85     ppr InfixN = ptext SLIT("infix")
86
87 instance Eq Fixity where                -- Used to determine if two fixities conflict
88   (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2
89
90
91 defaultFixity = Fixity 9 InfixL
92 \end{code}
93
94
95 %************************************************************************
96 %*                                                                      *
97 \subsection[NewType/DataType]{NewType/DataType flag}
98 %*                                                                      *
99 %************************************************************************
100
101 \begin{code}
102 data NewOrData
103   = NewType     -- "newtype Blah ..."
104   | DataType    -- "data Blah ..."
105   | EnumType    -- Enumeration; all constructors are nullary
106   deriving( Eq )        -- Needed because Demand derives Eq
107 \end{code}
108
109 %************************************************************************
110 %*                                                                      *
111 \subsection[Top-level/local]{Top-level/not-top level flag}
112 %*                                                                      *
113 %************************************************************************
114
115 \begin{code}
116 data TopLevelFlag
117   = TopLevel
118   | NotTopLevel
119
120 isTopLevel, isNotTopLevel :: TopLevelFlag -> Bool
121
122 isNotTopLevel NotTopLevel = True
123 isNotTopLevel TopLevel    = False
124
125 isTopLevel TopLevel     = True
126 isTopLevel NotTopLevel  = False
127 \end{code}
128
129 %************************************************************************
130 %*                                                                      *
131 \subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag}
132 %*                                                                      *
133 %************************************************************************
134
135 \begin{code} 
136 data RecFlag = Recursive 
137              | NonRecursive
138
139 isRec :: RecFlag -> Bool
140 isRec Recursive    = True
141 isRec NonRecursive = False
142
143 isNonRec :: RecFlag -> Bool
144 isNonRec Recursive    = False
145 isNonRec NonRecursive = True
146 \end{code}