[project @ 1999-07-26 15:31:01 by simonpj]
[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, negateFixity, negatePrecedence,
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
94 negateFixity :: Fixity
95 negateFixity     = Fixity negatePrecedence InfixL       -- Precedence of unary negate is wired in as infixl 6!
96
97 negatePrecedence :: Int
98 negatePrecedence = 6
99 \end{code}
100
101
102 %************************************************************************
103 %*                                                                      *
104 \subsection[NewType/DataType]{NewType/DataType flag}
105 %*                                                                      *
106 %************************************************************************
107
108 \begin{code}
109 data NewOrData
110   = NewType     -- "newtype Blah ..."
111   | DataType    -- "data Blah ..."
112   | EnumType    -- Enumeration; all constructors are nullary
113   deriving( Eq )        -- Needed because Demand derives Eq
114 \end{code}
115
116 %************************************************************************
117 %*                                                                      *
118 \subsection[Top-level/local]{Top-level/not-top level flag}
119 %*                                                                      *
120 %************************************************************************
121
122 \begin{code}
123 data TopLevelFlag
124   = TopLevel
125   | NotTopLevel
126
127 isTopLevel, isNotTopLevel :: TopLevelFlag -> Bool
128
129 isNotTopLevel NotTopLevel = True
130 isNotTopLevel TopLevel    = False
131
132 isTopLevel TopLevel     = True
133 isTopLevel NotTopLevel  = False
134 \end{code}
135
136 %************************************************************************
137 %*                                                                      *
138 \subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag}
139 %*                                                                      *
140 %************************************************************************
141
142 \begin{code} 
143 data RecFlag = Recursive 
144              | NonRecursive
145
146 isRec :: RecFlag -> Bool
147 isRec Recursive    = True
148 isRec NonRecursive = False
149
150 isNonRec :: RecFlag -> Bool
151 isNonRec Recursive    = False
152 isNonRec NonRecursive = True
153 \end{code}