cd07f5745bc7588e72445d5b5faba5df935454e2
[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(..), 
20         defaultFixity, maxPrecedence,
21         NewOrData(..), 
22         RecFlag(..), isRec, isNonRec,
23         TopLevelFlag(..), isTopLevel, isNotTopLevel
24    ) where
25
26 #include "HsVersions.h"
27
28 import Outputable
29 \end{code}
30
31 %************************************************************************
32 %*                                                                      *
33 \subsection[Unused]{Unused}
34 %*                                                                      *
35 %************************************************************************
36
37 Used as a placeholder in types.
38
39 \begin{code}
40 type Unused = ()
41
42 unused :: Unused
43 unused = error "Unused is used!"
44 \end{code}
45
46
47 %************************************************************************
48 %*                                                                      *
49 \subsection[Arity]{Arity}
50 %*                                                                      *
51 %************************************************************************
52
53 \begin{code}
54 type Arity = Int
55 \end{code}
56
57
58 %************************************************************************
59 %*                                                                      *
60 \subsection[Version]{Module and identifier version numbers}
61 %*                                                                      *
62 %************************************************************************
63
64 \begin{code}
65 type Version = Int
66 \end{code}
67
68
69 %************************************************************************
70 %*                                                                      *
71 \subsection[Fixity]{Fixity info}
72 %*                                                                      *
73 %************************************************************************
74
75 \begin{code}
76 data Fixity = Fixity Int FixityDirection
77 data FixityDirection = InfixL | InfixR | InfixN 
78                      deriving(Eq)
79
80 instance Outputable Fixity where
81     ppr (Fixity prec dir) = hcat [ppr dir, space, int prec]
82
83 instance Outputable FixityDirection where
84     ppr InfixL = ptext SLIT("infixl")
85     ppr InfixR = ptext SLIT("infixr")
86     ppr InfixN = ptext SLIT("infix")
87
88 instance Eq Fixity where                -- Used to determine if two fixities conflict
89   (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2
90
91 maxPrecedence = (9::Int)
92 defaultFixity = Fixity maxPrecedence InfixL
93 \end{code}
94
95
96 %************************************************************************
97 %*                                                                      *
98 \subsection[NewType/DataType]{NewType/DataType flag}
99 %*                                                                      *
100 %************************************************************************
101
102 \begin{code}
103 data NewOrData
104   = NewType     -- "newtype Blah ..."
105   | DataType    -- "data Blah ..."
106   | EnumType    -- Enumeration; all constructors are nullary
107   deriving( Eq )        -- Needed because Demand derives Eq
108 \end{code}
109
110 %************************************************************************
111 %*                                                                      *
112 \subsection[Top-level/local]{Top-level/not-top level flag}
113 %*                                                                      *
114 %************************************************************************
115
116 \begin{code}
117 data TopLevelFlag
118   = TopLevel
119   | NotTopLevel
120
121 isTopLevel, isNotTopLevel :: TopLevelFlag -> Bool
122
123 isNotTopLevel NotTopLevel = True
124 isNotTopLevel TopLevel    = False
125
126 isTopLevel TopLevel     = True
127 isTopLevel NotTopLevel  = False
128 \end{code}
129
130 %************************************************************************
131 %*                                                                      *
132 \subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag}
133 %*                                                                      *
134 %************************************************************************
135
136 \begin{code} 
137 data RecFlag = Recursive 
138              | NonRecursive
139
140 isRec :: RecFlag -> Bool
141 isRec Recursive    = True
142 isRec NonRecursive = False
143
144 isNonRec :: RecFlag -> Bool
145 isNonRec Recursive    = False
146 isNonRec NonRecursive = True
147 \end{code}