Haskell 98 vs. Glasgow Haskell: language non-compliance
GHC vs the Haskell 98 languageHaskell 98 language vs GHC
This section lists Glasgow Haskell infelicities in its implementation
of Haskell 98. See also the “when things go wrong” section
()
for information about crashes, space leaks, and other undesirable
phenomena.
The limitations here are listed in Haskell-Report order (roughly).
Lexical syntaxThe Haskell report specifies that programs may be
written using Unicode. GHC only accepts the ISO-8859-1
character set at the moment.Certain lexical rules regarding qualified identifiers
are slightly different in GHC compared to the Haskell report.
When you have
module.reservedop,
such as M.\, GHC will interpret it as a
single qualified operator rather than the two lexemes
M and .\.Context-free syntaxGHC doesn't do fixity resolution on the left hand side
of a binding before deciding which symbol is the function
symbol. For example, the following fails, because GHC makes
the assumption that the function symbol is
|-:
infix 5 |-
infix 9 :=
data Equal = Char := Int
0 |- x:=y = 1 |- x:=y -- XXX fails here
GHC doesn't do fixity resolution in expressions during
parsing. For example, according to the Haskell report, the
following expression is legal Haskell:
let x = 42 in x == 42 == True
and parses as:
(let x = 42 in x == 42) == True
because according to the report, the let
expression extends as far to the right as
possible. Since it can't extend past the second
equals sign without causing a parse error
(== is non-fix), the
let-expression must terminate there. GHC
simply gobbles up the whole expression, parsing like this:
(let x = 42 in x == 42 == True)
The Haskell report is arguably wrong here, but nevertheless
it's a difference between GHC & Haskell 98.Expressions and patterns
Very long String constants:
May not go through. If you add a “string gap” every
few thousand characters, then the strings can be as long
as you like.
Bear in mind that string gaps and the -cpp option
option don't mix very well (see ).
Single quotes in module names:
It might work, but it's just begging for trouble.
Declarations and bindings
None known.
Module system and interface files
Namespace pollution
Several modules internal to GHC are visible in the standard namespace.
All of these modules begin with Prel, so the rule
is: don't use any modules beginning with Prel in
your program, or you will be comprehensively screwed.
Numbers, basic types, and built-in classes
Unchecked arithmetic:
Arguably not an infelicity, but… Bear in
mind that operations on Int,
Float, and Double numbers are
unchecked for overflow, underflow, and other sad
occurrences. (note, however that some architectures trap
floating-point overflow and loss-of-precision and report a
floating-point exception, probably terminating the
program)floating-point
exceptions.
Use Integer, Rational, etc.,
numeric types if this stuff keeps you awake at night.
Multiply-defined array elements—not checked:
This code fragment should elicit a fatal error, but it does not:
main = print (array (1,1) [(1,2), (1,3)])
In Prelude support
The Char typeCharsize
ofThe Haskell report says that the
Char type holds 16 bits. GHC follows
the ISO-10646 standard a little more closely:
maxBound :: Char in GHC is
0x10FFFF.Arbitrary-sized tuples:
Tuples are currently limited to size 61. HOWEVER: standard instances
for tuples (Eq, Ord,
Bounded, IxRead, and Show) are available
only up to 5-tuples.
These limitations are easily subvertible, so please ask if you get
stuck on them.