1 <sect1 id="vs-Haskell-defn">
2 <title>Haskell 98 vs. Glasgow Haskell: language non-compliance
5 <indexterm><primary>GHC vs the Haskell 98 language</primary></indexterm>
6 <indexterm><primary>Haskell 98 language vs GHC</primary></indexterm>
8 <para>This section lists Glasgow Haskell infelicities in its
9 implementation of Haskell 98. See also the “when things
10 go wrong” section (<XRef LinkEnd="wrong">) for information
11 about crashes, space leaks, and other undesirable phenomena.</para>
13 <para>The limitations here are listed in Haskell-Report order
16 <sect2 id="haskell98-divergence">
17 <title>Divergence from Haskell 98</title>
20 <sect3 id="infelicities-lexical">
21 <title>Lexical syntax</title>
25 <para>The Haskell report specifies that programs may be
26 written using Unicode. GHC only accepts the ISO-8859-1
27 character set at the moment.</para>
31 <para>Certain lexical rules regarding qualified identifiers
32 are slightly different in GHC compared to the Haskell
34 <replaceable>module</replaceable><literal>.</literal><replaceable>reservedop</replaceable>,
35 such as <literal>M.\</literal>, GHC will interpret it as a
36 single qualified operator rather than the two lexemes
37 <literal>M</literal> and <literal>.\</literal>.</para>
42 <sect3 id="infelicities-syntax">
43 <title>Context-free syntax</title>
47 <para>GHC doesn't do fixity resolution in expressions during
48 parsing. For example, according to the Haskell report, the
49 following expression is legal Haskell:
51 let x = 42 in x == 42 == True</programlisting>
54 (let x = 42 in x == 42) == True</programlisting>
56 because according to the report, the <literal>let</literal>
57 expression <quote>extends as far to the right as
58 possible</quote>. Since it can't extend past the second
59 equals sign without causing a parse error
60 (<literal>==</literal> is non-fix), the
61 <literal>let</literal>-expression must terminate there. GHC
62 simply gobbles up the whole expression, parsing like this:
64 (let x = 42 in x == 42 == True)</programlisting>
66 The Haskell report is arguably wrong here, but nevertheless
67 it's a difference between GHC & Haskell 98.</para>
72 <sect3 id="infelicities-exprs-pats">
73 <title>Expressions and patterns</title>
77 <term>Very long <literal>String</literal> constants:</term>
79 <para>May not go through. If you add a “string
80 gap” every few thousand characters, then the strings
81 can be as long as you like.</para>
83 <para>Bear in mind that string gaps and the
84 <option>-cpp</option><indexterm><primary><option>-cpp</option>
85 </primary></indexterm> option don't mix very well (see
86 <xref linkend="c-pre-processor">).</para>
93 <sect3 id="infelicities-decls">
94 <title>Declarations and bindings</title>
96 <para>None known.</para>
100 <sect3 id="infelicities-Modules">
101 <title>Module system and interface files</title>
106 <term> Namespace pollution </term>
108 <para>Several modules internal to GHC are visible in the
109 standard namespace. All of these modules begin with
110 <literal>Prel</literal>, so the rule is: don't use any
111 modules beginning with <literal>Prel</literal> in your
112 program, or you will be comprehensively screwed.</para>
119 <sect3 id="infelicities-numbers">
120 <title>Numbers, basic types, and built-in classes</title>
124 <term>Multiply-defined array elements—not checked:</term>
126 <para>This code fragment <emphasis>should</emphasis>
127 elicit a fatal error, but it does not:
130 main = print (array (1,1) [(1,2), (1,3)])</programlisting>
139 <sect3 id="infelicities-Prelude">
140 <title>In Prelude support</title>
144 <term>The <literal>Char</literal> type</term>
145 <indexterm><primary><literal>Char</literal></primary><secondary>size
146 of</secondary></indexterm>
148 <para>The Haskell report says that the
149 <literal>Char</literal> type holds 16 bits. GHC follows
150 the ISO-10646 standard a little more closely:
151 <literal>maxBound :: Char</literal> in GHC is
152 <literal>0x10FFFF</literal>.</para>
157 <term>Arbitrary-sized tuples:</term>
159 <para>Tuples are currently limited to size 61. HOWEVER:
160 standard instances for tuples (<literal>Eq</literal>,
161 <literal>Ord</literal>, <literal>Bounded</literal>,
162 <literal>Ix</literal> <literal>Read</literal>, and
163 <literal>Show</literal>) are available
164 <emphasis>only</emphasis> up to 5-tuples.</para>
166 <para>This limitation is easily subvertible, so please ask
167 if you get stuck on it.</para>
174 <sect2 id="haskell98-undefined">
175 <title>GHC's interpretation of undefined behaviour in
176 Haskell 98</title>
178 <para>This section documents GHC's take on various issues that are
179 left undefined or implementation specific in Haskell 98.</para>
183 <term>Sized integral types</term>
184 <indexterm><primary><literal>Int</literal></primary><secondary>size of</secondary>
188 <para>In GHC the <literal>Int</literal> type follows the
189 size of an address on the host architecture; in other words
190 it holds 32 bits on a 32-bit machine, and 64-bits on a
191 64-bit machine.</para>
193 <para>Arithmetic on <literal>Int</literal> is unchecked for
194 overflow<indexterm><primary>overflow</primary><secondary><literal>Int</literal></secondary>
195 </indexterm>, so all operations on <literal>Int</literal> happen
197 2<superscript><replaceable>n</replaceable></superscript>
198 where <replaceable>n</replaceable> is the size in bits of
199 the <literal>Int</literal> type.</para>
201 <para>The <literal>fromInteger</literal><indexterm><primary><literal>fromInteger</literal></primary>
202 </indexterm>function (and hence
203 also <literal>fromIntegral</literal><indexterm><primary><literal>fromIntegral</literal></primary>
204 </indexterm>) is a special case when
205 converting to <literal>Int</literal>. The value of
206 <literal>fromIntegral x :: Int</literal> is given by taking
207 the lower <replaceable>n</replaceable> bits of <literal>(abs
208 x)</literal>, multiplied by the sign of <literal>x</literal>
209 (in 2's complement <replaceable>n</replaceable>-bit
210 arithmetic). This behaviour was chosen so that for example
211 writing <literal>0xffffffff :: Int</literal> preserves the
212 bit-pattern in the resulting <literal>Int</literal>.</para>
217 <term>Unchecked float arithmetic</term>
219 <para>Operations on <literal>Float</literal> and
220 <literal>Double</literal> numbers are
221 <emphasis>unchecked</emphasis> for overflow, underflow, and
222 other sad occurrences. (note, however that some
223 architectures trap floating-point overflow and
224 loss-of-precision and report a floating-point exception,
225 probably terminating the
226 program)<indexterm><primary>floating-point
227 exceptions</primary></indexterm>.</para>
237 ;;; Local Variables: ***
239 ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter" "sect1") ***