- Title page. Remove "[editor]" from after John Hughes.
- Title page. Add the paragraph:
"Copyright (c) Simon Peyton Jones.
The authors intend this Report to belong to the entire Haskell
community, and so we grant permission to copy and
distribute it for any purpose, provided that it is
reproduced in its entireity, including this Notice. Modified
versions of this Report may also be copied and distributed for any purpose,
provided that the modified version is clearly presented as such,
and that it does not claim to be a definition of the language Haskell 98."
- [Aug 2001] Page 2, The Haskell Kernel.
Replace the entire section with the following:
"Haskell has adopted many of the convenient syntactic structures
that have become popular
in functional programming. In this Report, the meaning of such
syntactic sugar is given by translation into simpler constructs.
If these translations are applied exhaustively, the result is a program
written in a small subset of Haskell that we call the Haskell kernel."
"Although the kernel is not formally specified, it is essentially a
slightly sugared variant of the lambda calculus with a straightforward
denotational semantics. The translation of each syntactic structure
into the kernel is given as the syntax is introduced. This modular
design facilitates reasoning about Haskell programs and provides
useful guidelines for implementors of the language."
(The intent here is to avoid the common misconception that the kernel
is a formally specified thing.)
- [Sept 2001] Page 2, Section 1.4, Namespaces; and
Page 7, Section 2.4, Identifiers and operators; and
Page 15, Section 3.2, Variables, Constructors, Operators, and Literals.
Remove the first paragraph (about operators), which does not really belong
here, and item 2 of the list (which is related).
Instead, amplify the remarks in Section 2.4 and 3.2. This is a presentational
change only.
- [Sept 2002] Page 4, Section 2.1, Notational conventions.
Remove the second-last paragraph altogether, which begins "Haskell uses a pre-processor...".
(No implementation does this, and the reference to escapes in identifiers is inconsistent
with the lexical syntax.)
- [Late Dec 2001] Page 5, Section 2.2, Lexical program structure; and Appendix B.2, p120.
Replace the production for "comment" with:
comment -> dashes [ any_<symbol> { any } \] newline
(This ensures that "--+", for example, does not start a comment.)
- [Dec 2001] Page 5, Section 2.2, Lexical program structure; and Appendix B.2, p120.
- Change the production for lexeme to
lexeme -> qvarid | qconid | qvarsym | qconsym | literal | special | reservedop | reservedid
- [March 02] Change the productions for whitechar and newline to:
whitechar -> newline | vertab | space | tab | uniWhite
newline -> return linefeed | return | linefeed | formfeed
(This means that CR, LF, or CRLF (remember maximal munch), are all valid 'newline' separators,
and the same sequence of characters should therefore work on any
Haskell implementation.)
- [March 02] Change the production for ANY to
ANY -> graphic | whitechar
(This is nicely similar to the production for "any".)
- Change the production for uniDigit to
uniDigit -> any Unicode decimal digit
- Change the production for symbol to:
symbol -> ascSymbol | uniSymbol< special | _ | : | " | ' >
- Add return, linefeed, and uniWhite to the production for ANY.
(These changes, and the next one, justify the productions for program which claims that a program is
a sequence of lexemes and white space.)
- [Feb 2002] Page 6, Section 2.2, Lexical program structure.
In the first paragraph, delete the phrase ", using a context-independent
deterministic lexical analysis (i.e.~no lookahead beyond the current character is
required)".
(The maximal munch rule is correct, but it's not true that it only takes one character
of lookahead. Consider
"F. 9. 0o 0x 9.0e+f", which
should lex as "F . 9 . 0 o 0 x 9.0 e + f" but that needs up to two additional characters
of lookahead.)
- Page 7, Section 2.4, Identifiers and operators; and Appendix B.2, p121.
Add dashes to reservedop in the exclusion set of the
production for varsym. (This ensures that "--" and
"---" are not legal lexemes.
- [Nov 2001] Page 7, Section 2.4, Identifiers and operators; and Appendix B.2, p121.
- Remove the productions for specialid and specialop
- Delete the paragraph about specialid and specialop near the bottom of page 7
("A few identifiers and operators..").
- [Nov 2001] Page 8, Section 2.5, Numeric literals; and Appendix B.2, p121.
Replace the production for "float" with:
float -> decimal . decimal [exponent]
| decimal exponent
exponent -> (e | E) [+ | -] decimal
(This change means that 20e3 is a floating-point literal. There is a corresponding change
to the lexer on p114.)
- Page 9, Section 2.4, Identifiers and operators; and Page 68, Section 5.5.1, Qualified names.
Move the first paragraph of 5.5.1, and the following table, and the paragraph starting "The qualifier does not change...",
to the end of Section 2.4. (These paragraphs deal with lexical matters, which do not belong in Chapter 5.)
- Page 9, Section 2.6, Character and String Literals.
In the production for "cntrl" replace "ASClarge" by "ascLarge".
- [Nov 2001] Page 9, Section 2.6, Characters and String Literals; and
Page 73, Section 6.1.2, Characters and strings
(This change removes the commitment to 16-bit Unicode. The result is that the Report
is even vaguer than before about the range of Unicode that a compiler is obliged to
accept, but this confusion is in large part Unicode's fault, and is not readily fixed
in a revision of this nature.)
- Page 10, Section 2.7, Layout.
In the middle of the third paragraph, just before the sentence beginning
"A close brace is also inserted...", add the following sentence:
"If the indentation of the non-brace lexeme immediately
following a where, let,
do or of is less than or equal to the current indentation level,
then instead of starting a layout, an empty list "{}" is inserted, and
layout processing occurs for the current level (i.e. insert a semicolon or close brace)."
- Page 11, Figures 1 and 2. In both figures the signature for size
should be
size :: Stack a -> Int
- [July 2001] Page 12, Section 3, Expressions.
Replace the last two sentences of the first paragrah of the section by:
"Free variables and constructors used in these translations always
refer to entities defined by the Prelude. For example,
``concatMap'' used in the translation of list comprehensions
(Section 3.11) means the concatMap defined by the
Prelude, regardless of what is in scope where the list
comprehension is used."
(Clarification only.)
- [May 2002] Page 12, Section 3, Expressions; also Page 17, Section 3.5;
also Page 128, Appendix B, Syntax.
Add the following two extra productions for aexp:
| '(' lexp(i) qop(l,i) ')' left section
| '(' qop(r,i)<-> rexp(i) ')' right section
and change the othe right-section production to:
| '(' qop(a,i)<-> exp(i+1) ')' right section
(This brings the formal syntax into line with the
words in Section 3.5. The grammar now follows the way that qfunlhs is defined.
There is no ambiguity, because an exp(i+1) is not an lexp(i).)
The exclusion of "-" from right sections is also new [May 2002]; it is necessary
to prevent overlap with the unary-minus syntax.
- [Aug 2001] Page 13, Section 3, Expressions.
Remove Table 1, and the associated paragraph beginning "As an aid to
understanding...". (The table causes more confusion than it clears up.)
- [March 2002] Page 14, Section 3, Expressions.
After the sample parses, add the following paragraphs:
A note about parsing. Expressions that involve the interaction
of fixities with the let/lambda meta-rule
may be hard to parse. For example, the expression
let x = True in x == x == True
cannot possibly mean
let x = True in (x == x == True)
because (==) is a non-associative operator; so the expression must parse thus:
(let x = True in (x == x)) == True
However, implementations may well use a post-parsing pass to deal with fixities,
so they may well incorrectly deliver the former parse. Programmers are advised
to avoid constructs whose parsing involves an interaction of (lack of) associativity
with the let/lambda meta-rule.
- [Nov 2001] Page 13, Section 3 Expressions.
Replace the curly braces by angle brackets, in the subscript of "aexp" in the last production of "aexp".
Similarly, on Page 26, Section 3.15.3; and Page 128, Appendix B.4.
- [Apr 2001] Page 14, Section 3.1, Errors. In the first sentence of
the section, after "indistinguishable" add "by a Haskell program".
- [Apr 2001] Page 15, Section 3.2, Variables, Constructors, Operators, and Literals.
Remove the paragraph starting "Qualified names may only ...", and the following example, and the
concluding paragraph starting "incorrectly uses a qualifier". (This is all covered in 2.4 and 5.5.1.)
- [May 2002] Page 17, Section 3.5, Sections.
Append the following to the paragraph beginning "Syntactic precedence rules apply to sections as follows."
"As another example, the expression
(let x = 10 in x +)
is invalid because, by the let/lambda meta-rule (Section 3)
the expression
(let n = 10 in n + x)
parses as
(let n = 10 in (n + x))
rather than
((let n = 10 in n) + x)
"
- [Oct 2001] Page 18, Section 3.7, Lists.
After the sentence starting "The constructor ":" is reserved solely for list construction...",
add the new sentence:
"It is a right-associative operator, with precedence level 5 (Section 4.4.2)."
(Otherwise this information is found only in the Prelude.)
- [July 2001] Page 20, Section 3.10, Arithmetic sequences.
In the second paragraph, in the sentence "For the type Integer,
arithmetic sequences have the following meaning...", replace "type Integer"
with "types Int and Integer". Remove Integer from the
list in the paragraph following the bulletted list.
- [Apr 2001] Page 21, Section 3.11, List Comprehensions; and Page 128.
- In the production for "aexp", change the "n >= 0" to "n >= 1".
- Remove the production for (empty qualifier)
- In the translation box lower down the page, rewrite the translation so
that it does not involve and empty list of qualifiers. (Unchanged semantics.)
This change ensures that there is at least one qualifier in list comprehension,
and no qualifier is empty. The translation lower down page 23 is then
not utterly rigorous, because Q can be empty, and when it is there is no preceding
comma, but I reckon it would make matters worse to "fix" it.
- [March 2002] Page 22, Section 3.13, Case Expressions.
To the end of the section, add the following paragraphs:
A note about parsing. The (type-incorrect) expression
case x of { (a,_) | let b = not a in b :: Bool -> a }
is tricky to parse correctly. It has a single unambiguous parse, namely
case x of { (a,b) | (let b = not a in b :: Bool) -> a }
However, the phrase Bool -> a is syntactically valid as a type, and
parsers with limited lookahead may incorrectly commit to this choice, and hence
reject the program. Programmers are advised, therefore, to avoid guards that
end with a type signature --- indeed that is why a "gd" contains
an "exp^0" not an "exp".
- [Apr 2001] Page 23, Section 3.14, Do Expressions;
and Page 128, Appendix B.4, Context Free Syntax.
That is, every list of statements must end in an expression, optionally
followed by a semicolon.
- [Aug 2001] Page 24, Section 3.15, Datatypes with Field Labels..
Add an example to illustrate the final point in para 2.
- [Feb 2002] Page 25, Section 3.15.2, Construction Using Field Labels.
At the end of the section add the sentence:
The expression F {}, where F is a data constructor, is legal
whether or not F was declared with record syntax, provided
F has no strict fields; it denotes
F _|_1 ... _|_n,
where n is the arity of F.
(This matches the dual for pattern matching, in Section 4.2.1.)
- [Aug 2001] Page 26, Section 3.15.3, Updates Using Field Labels.
In the translation box:
- replace the first un-subscripted "C" by "C1", and the second by "Cj".
(The "1" and "j" should be subscripts of course!)
- Change "b" to "bs" in the "where..." part.
- [Aug 2001] Page 28, Section 3.17.1, Patterns..
Give an example to illustrate an illegal non-linear pattern.
- [Jan 2002] Page 29, Section 3.17.2, Informal Semantics of Case Expressions.
Reword the entire numbered list giving the informal semantics, so that:
- It is clearly classified by pattern.
- The semantics of matching a newtype pattern against bottom is given.
- A literal and n+k pattern may not diverge even if the value matched is bottom; it
depends on the definition of == and >= respectively.
- [Aug 2001] Page 31, Section 3.17.2, Informal Semantics of Case Expressions.
Replace the example at the foot of Page 31, following the paragraph "The guard semantics...",
with the following:
f :: (Int,Int,Int) -> [Int] -> Int
f ~(x,y,z) [a] | (a == y) = 1
(The previous example use boolean and, which is non-strict in its second argument!)
- [Apr 2001] Page 31,33, Figures 3 and 4, Semantics of Case Expressions.
Replace "completely new variable" by "new variable" in these two figures. (Some clauses
said "new" and some "completely new" which is misleadingly inconsistent.)
- [Apr 2001] Page 33, Figure 4, Semantics of Case Expressions Part 2.
In clause (r) replace "e0" by "v" throughout.
- [Jan 2002] Page 33, Figure 4, Semantics of Case Expressions Part 2.
- [May 2002] Page 34, Section 4, Declarations and Bindings;
and Page 44, Section 4.3.1, Class Declarations.
In the production for class, replace
class [scontext =>] simpleclass [where decls]
by
class [scontext =>] tycls tyvar [where decls]
- [Sept 2001] Page 36, Section 4.1.2, Syntax of Types.
First paragraph, last sentence. After "infix type constructors are not allowed",
add "(other than (->))".
- [Oct 2001] Page 38, Section 4.1.2, Algebraic Datatype Declarations.
Replace the sentence
"Although the tuple, list, and function types have special syntax, they
are not different from user-defined types with equivalent
functionality."
with
"These special syntactic forms always denote the built-in type constructors
for functions, tuples, and lists, regardless of what is in scope.
In a similar way, the prefix type constructors (->),, [], (), (,),
and so on, always denote the built-in type constructors; they
cannot be qualified, nor mentioned in import or export lists (Section 5).
(Hence the special production, gtycon, above.)
"Although the tuple and list types have special syntax, their semantics
is the same as the equivalent user-defined algebraic data types."
(This stuff is clarification only.)
- Page 40, Section 4.2.1, Algebraic Datatype Declarations.
In the bottom paragraph on the page, before "The context in the data declaration
has no other effect whatsoever" add the following:
"Pattern matching against ConsSet also gives rise to an Eq a
constraint. For example:
f (ConsSet a s) = a
the function f has inferred type Eq a => Set a -> a."
- Page 41, Section 4.2.1, subsection Labelled Fields.
At the end of the subsection, add a new paragraph:
"The pattern "F {}" matches any value built with constructor F,
whether or not F was declared with record syntax."
- [Nov 2001] Page 41, Section 4.2.1, subsection Strictness Flags.
Add the following sentence at the end of the pargraph:
"Lexically, "!" is an ordinary varsym not a reservedop;
it has special significance only in the context of the argument types of
a data declaration."
- [Apr 2001] Page 42, Section 4.2.1, subsection Labelled Fields.
Change "occurance" to "occurrence" in the translation box at the very end of
the section.
- [Late Dec 2001] Page 46, Section 4.3.2, Instance Declarations.
- Remove the production for "qfunlhs".
- Replace the first production for "idecl" by:
idecl -> (funlhs | var) rhs
(i.e. omitting the alternatives for "qvar" and "qfunlhs").
- In the third paragraph from the bottom, delete the text starting "However, unlike
other declarations, the name of the bound variable may be qualified..." and ending at
"Hence the need for the qfunlhs and qvar left hand sides for an idecl.".
- In place of the deleted sentences, add the following:
"It is illegal to give a
binding for a class method that is not in scope, but the name under
which it is in scope is immaterial; in particular, it may be a qualified
name. (This rule is identical to that used for subordinate names in
export lists --- Section 5.2.)
For example, this is legal, even though return is in scope only
with the qualified name Monad.return.
module A where
import qualified Monad
instance Monad.Monad T where
return = ...
(>>=) = ...
"
- Make the same syntactic changes to the syntax in Appendix B.4.
(This signficant change removes a wart from the language. Instead of requiring a qualified
name on the LHS of an instance declaration if the method name is in scope in more than
one way, the context is now used to disambiguate. This is compatible with the story
for type signatures, Section 4.4.1.)
- [Late Dec 2001] Page 49, Section 4.3.4, Ambiguous Types... In the third paragraph
from the end of 4.3.4, replace "monotype" by "type".
- Page 49, Section 4.3.4, Ambiguous Types...
In the third paragraph from the end of Section 4.3.4, replace "...an ambiguous
type variable is defaultable if at least one of its classes is a numeric class..."
by "...an ambiguous type variable, v, is defaultable if v appears only in constraints
of the form (C v), where C is a class, and if at least one of its classes is
a numeric class...".
The new phrase is "if v appears only in constraints of the
form (C v) where C is a class". Without this condition the rest of the
sentence does not make sense.
- [Aug 2001] Page 51, Section 4.4.2, Fixity Declarations.
- In the prodution for gendecl change digit to integer.
- Make the same change in the syntax at the start of Section 4 and in Appendix B.
- After "A fixity declaration gives the fixity and binding
precedence of one or more operators." add the sentence "The integer in a fixity declaration
must be in the range 0 to 9."
(Previously, "digit" was used, and it isn't a lexeme.)
- [Apr 2001] Page 53, Section 4.4.3. Replace "For example, these two function
definitions are equivalent:", and the two lines of code that follow by:
"For example, these three function definitions are all equivalent:
plus x y z = x+y+z
x `plus` y = \ z -> x+y+z
(x `plus` y) z = x+y+z
"
(This change makes explicit that an infix operator with more than two arguments
can have all of them on the LHS.)
- [Apr 2001] Page 54, Section 4.4.3, subsection Function Bindings.
In the first translation scheme ("The general binding form for functions..."),
the xn should be xk (suitably subscripted in both cases!),
and all three m subscripts should be n.
- Page 57, Section 4.5.3, Context reduction errors.
The example
f :: (Monad m, Eq (m a)) => a -> m a -> Bool
f x y = x == return y
is wrong; it should read
f x y = return x == y
- [Sept 2001] Page 58, Section 4.5.5, Momomorphism.
In the boxed text entitled "The monomorphism restriction", replace
"The usual Hindley-Milner restriction on polymorphism is that only
type variables free in the environment may be generalized" by
"The usual Hindley-Milner restriction on polymorphism is that only
type variables that do not occur free in the environment may be generalized."
(The sense was backward before.)
- [May 2001] Page 62, Section 5, Modules.
In paragraph 4, add a footnote to the sentence "A multi-module Haskell
program can be converted into a single-module program by ...", namely:
"There are two minor exceptions to this statement.
First, default declarations scope over a single module (Section 4.3.4).
Second, Rule 2 of the monomorphism restriction (Section 4.5.5)
is affected by module boundaries."
This footnote qualifies the otherwise over-strong statement.
- [Late Dec 2001] Page 63,64, Section 5.2, Export lists.
- In the production for "export", replace "qcname" by "cname" (and similarly in Appendix B.4).
- In the production for "qcname", replace "qcname" by "cname", "qvar" by "var", and "qcon" by "con".
In Appendix B.4 delete the production for "qcname".
- In the second bulleted item under point (2) of the numbered items, replace "qcname" by "c", throughout.
- In point (2) of the numbered items, add the following:
"In all cases, the (possibly-qualified) type constructor T must be in scope.
The constructor and field names c_i in the second form are unqualified;
one of these subordinate names is legal if and only if (a) it names a constructor
or field of T, and (b) the constructor or field
is in scope in the module body regardless of whether it is in scope
under a qualified or unqualified name. For example, the following is
legal
module A( Mb.Maybe( Nothing, Just ) ) where
import qualified Maybe as Mb
"
- Make a similar change to point (4).
- In points (1)-(4), make it clear that the variable, type constructor, or class must be in scope.
(These changes clarify the scope rules for export lists. Much email discussion during Dec 2001.)
- [March 02] In point (2) delete the sentence "The qcnamei must not conatin duplications.".
Make a similar change in point (4).
- [Oct 2001, modified Nov 2002] Page 64, Section 5.2, Export declarations, numbered items 5 and 6.
Replace both items with the following:
The form "module M" names the set of all entities that are in
scope with both an unqualified name "e" and a qualified name
"M.e".
This set
may be empty.
For example:
module Queue( module Stack, enqueue, dequeue ) where
import Stack
...
"Here the module Queue uses the module name Stack in its export
list to abbreviate all the entities imported from Stack.
"A module can name its own local definitions in its export
list using its own name in the `module M'' syntax, because a local
declaration brings into scope both a qualified and unqualified name.
For example:
module Mod1( module Mod1, module Mod2 ) where
import Mod2
import Mod3
"Here module Mod1 exports all local definitions as well as those
imported from Mod2 but not those imported from Mod3."
It is an error to use module M in an export list unless M is
the module bearing the export list, or M is imported by at
least one import declaration (qualified or unqualified).
- [July 2001] Page 65, Section 5.2, Export declarations.
Replace the two paragraphs and code fragment that the numbered list with the following:
"It makes no difference to an importing module how an entity was
exported. For example, a field name f from data type T may be exported individually
(f, item (1) above); or as an explicitly-named member of its data type (T(f), item (2));
or as an implicitly-named member (T(..) item(2)); or by exporting an entire
module (module M, item (5)).
Exports lists are cumulative: the set of entities exported by an export
list is the union of the entities exported by the individual items of the list.
The unqualified names of the entities exported by a module must all be distinct
(within their respective namespace). For example
module A ( C.f, C.g, g, module B ) where -- an invalid module
import B(f)
import qualified C(f,g)
g = f True
There are name clashes in the export list
between C.g and g,
and between module B and C.f (assuming B.f and C.f are different entities),
even though there are no name clashes within module A itself.
- [Feb 2002] Page 65, Section 5.3, Import Declarations, syntax; also page 125, Appendix B.4.
In the second production for "import", namely "tycon [ [(..)] | (cname1, ..., cnamen)]"
replace "n>=1" by "n>=0". (There is no need to require one or more constructors, and
in hiding clauses it may be useful to hide the type constructor only.)
- [Nov 2001] Page 65, Section 5.3, Import Declarations, last line.
Before "Exactly which entities are to be imported..." add a new paragraph:
"Lexically speaking, the terminal symbols "as", "qualified" and
"hiding" are each a "varid" rather than a "reservedid". They have
special significance only in the context of an import declaration;
they may also be used as variables."
- [July 2001] Page 65, Section 5.3, Import Declarations, last line.
Start a new subsection "5.3.1 What is imported" before "Exactly which entities are to
be imported...".
- [July 2001] Page 66, Section 5.3, Import Declarations, numbered item 2.
Delete the two sentences "The hiding clause only applies to unqualified
names... A hiding clause has no effect....".
- [Oct 2001] Page 66, Section 5.3, Import Declarations, numbered item 2.
Add "It is an error to hide an entity that is not, in fact, exported by
the imported module."
- [July 2001] Page 66, Section 5.3.1, Qualified Import. [This section
becomes 5.3.2.] Replace the first sentence with:
"For each entity imported under the rules of Section 5.3.1
the top-level environment is extended. If the import declaration used
the qualified keyword, only the qualified name of the entity is
brought into scope. If the qualified keyword is omitted, then both the
qualified and unqualified name of the entity is brought into scope.
Section 5.5.1 describes qualified names in more detail."
- Page 67, Section 5.3.2, Local aliases.
The last example in the section should read:
import Foo as A(f)
- [Aug 2001] Page 68, Section 5.5.1, Qualified names.
Replace the second example in the first bullet by:
module M where
M.f x = ... -- ILLEGAL
g x = let M.y = x+1 in ... -- ILLEGAL
(This just clarifies that qualifiers aren't legal in local decls either.)
- Page 69, Section 5.5.2, Name clashes.
At the very end of the section, add the following clarification:
"The name occurring in a type signature or fixity declarations is always
unqualified, and unambiguously refers to another declaration in the
same declaration list (except that the fixity declaration for a class method
can occur at top level --- Section 4.4.2). For example, the following
module is legal:
module F where
sin :: Float -> Float
sin x = (x::Float)
f x = Prelude.sin (F.sin x)
The local declaration for sin is legal, even though
the Prelude function sin is implicitly in scope.
The references to
Prelude.sin and F.sin must both be qualified to make
it unambigous which sin is meant.
However, the unqualified name "sin" in the type
signature in the first line of F unambiguously refers to the
local declaration for sin."
- [Nov 2001] Page 71, Section 5.6.1, The Prelude module.
Replace the entire first paragraph of the section with:
"The Prelude module is imported automatically into all modules as if
by the statement `import Prelude', if and only if it is not imported
with an explicit import declaration. This provision for explicit
import allows entities defined in the Prelude to be selectively imported,
just like those from any other module."
- [May 2002] Page 71, Section 5.6.2, Shadowing Prelude Names.
Replace the entire section with the following, which clarifies matters considerably
compared to the original Haskell 98 Report.
"
module A( null, nonNull ) where
import Prelude hiding( null )
null, nonNull :: Int -> Bool
null x = x == 0
nonNull x = not (null x)
Module A redefines null, and contains an unqualified reference
to null on the right hand side of nonNull.
The latter would be ambiguous without the "hiding(null)" on the
"import Prelude" statement.
Every module that imports A unqualified, and then makes an unqualified
reference to null must also resolve the ambiguous use of null
just as A does. Thus there is little danger of accidentally shadowing
Prelude names.
"It is possible to construct and use a different module to serve in
place of the Prelude. Other than the fact that it is implicitly
imported, the Prelude is an ordinary Haskell module; it is special
only in that some objects in the Prelude are referenced by special
syntactic constructs. Redefining names used by the Prelude does not
affect the meaning of these special constructs. For example, in
module B where
import Prelude()
import MyPrelude
f x = (x,x)
g x = (,) x x
h x = [x] ++ []
the explicit import Prelude() declaration prevents the automatic
import of Prelude, while the declaration import MyPrelude brings the
non-standard prelude into scope.
The special syntax for tuples (such as (x,x) and (,)) and lists
(such as [x] and []) continues to refer to the tuples and lists
defined by the standard Prelude;
there is no way to redefine the meaning of [x], for example, in terms of a
different implementation of lists.
On the other hand, the use of ++ is not special syntax, so it refers
to ++ imported from MyPrelude.
"It is not possible, however, to hide instance declarations in the
Prelude. For example, one cannot define a new instance for Show Char."
- [Aug 2001] Page 74, Section 6.1.3, Lists. In the last sentence,
after "Monad" add ", Functor". (The list type is an instance of Functor.)
- [May 2001] Page 74, Section 6.1.4, Tuples.
Replace the first paragraph of this section with:
"Tuples are algebraic datatypes with special syntax, as defined
in Section 3.8. Each tuple type has a single constructor.
All tuples are instances of Eq, Ord, Bounded, Read,
Show (provided, of course, that all their component types are).
There is no upper bound on the size of a tuple, but some Haskell
implementations may restrict the size of tuples, and limit the
instances associated with larger tuples. However, every Haskell
implementation must support tuples up to size 15, together with their instances
for Eq, Ord, Bounded, Read,
and Show. The Prelude and
libraries define tuple functions such as zip for tuples up to a size
of 7."
- [Apr 2001] Page 74, Section 6.1.6, Function Types.
Delete the sentence "Functions are an instance of the Show class but not Read".
- [Aug 2001] Page 75, Section 6.1.7, The IO and IOError Types.
In the second sentence, replace "Show" by "Functor".
(IO is an instance of Functor, but not Show.)
- [Apr 2001] Page 76, Section 6.3, Standard Haskell classes.
There is a formatting error in the example. There should be a new line
after "the declaration of Class Eq is:", and before the sentence beginning
"This declaration gives default method declarations...".
- [July 2001] Page 78, Section 6.3.2, The Ord Class.
Redefine the default methods for max and min as follows:
max x y | x <= y = y
| otherwise = x
min x y | x <= y = x
| otherwise = y
(This change aligns the report with the code given in the Appendix.)
- [Apr 2001] Page 78, Section 6.3.3, The Read and Show Classes.
After "The Read and Show classes are used to convert values
to and from strings." add the sentence:
"The Int argument to showsPrec and readsPrec gives the operator
precedence of the enclosing context (see Appendix D.4)."
(Clarification only.)
- [May 2002] Page 79, Section 6.3.3, The Read and Show Classes.
Add documentation for the function lex:
"The function lex :: ReadS String, used by read, is also part of the Prelude.
It reads a single lexeme from the input, discarding initial white space, and
returning the characters that constitute the lexeme. If the input string contains
only white space, lex returns a single successful ``lexeme'' consisting of the
empty string. (Thus lex "" = [("","")].) If there is no legal lexeme at the
beginning of the input string, lex fails (i.e. returns [])."
- [Nov 2001] Page 79, Section 6.3.4, Class Enum;
Page 19, Section 3.10 Arithmetic Sequences; and Appendix D.2, Derived instances of Enum.
- Move the specification of the Int and Integer instances of
Enum from 3.10 to 6.3.4.
- Specify that, for bounded types, succ and pred should fail
when applied to maxBound and minBound resp.
- Specify that the enum functions on numeric types are strict.
- Remove material from D.2 so that it describes only the derived instances.
This change amounts to a fairly complete rewrite of 6.3.4, with a slightly tighter
specification than before.
- Page 80, Section 6.3.6, Class Monad.
Right at the bottom of the page, replace "However, for IO, the fail
method invokes error." by "For IO, the fail method raises a user
exception in the IO monad (see Section 7.3)."
- [Aug 2001] Page 82, Section 6.4, Numbers.In paragraph 2 of 6.4, replace "Rational library"
with "Ratio library".
- [July 2001] Page 83, Section 6.4.2, Arithmetic and number-theoretic operations.
After "The quod, rem, div, and mod class methods satisfy these laws" add "if y is non-zero".
- [Apr 2001] Page 84, Section 6.4, Fig 7; and bottom of page 86, Section 6.4.6.
fromRealFrac :: (RealFrac a, Fractional b) => a -> b
should be replaced by
realToFrac :: (Real a, Fractional b) => a -> b
- [Late Dec 2001] Page 84, Section 6.4.2, gcd.
In the final paragraph of 6.4.2, replace "gcd x y is the greatest integer
that divides both x and y" by "gcd x y is the greatest (positive) integer
that divides both x and y. gcd 0 0 raises a runtime error".
(The "(positive)" clarifies a slightly ambiguous point, while the specification for
gcd 0 0 remains controversial.
There was a lot of email on the Haskell mailing list in Dec 2001 about the latter point.)
- Page 88, Section 7.1, Standard I/O functions.
In the section "Input functions" replace "the IOError value associated
with end-of-file is defined in a library" by "a predicate isEOFError that
identifies this exception is defined in the IO library".
- [May 2002] Page 88, Section 7.1, Standard I/O functions.
In the section "Input functions",
- Change "Both getChar and getLine raise an exception on end-of-file;" to
"The getChar operation raises an exception on end-of-file;".
- After that sentence, add the further sentence "The getLine operation raises
an exception under the same circumstances as hGetLine, defined the IO library."
(This change goes along with a more precise description of the behaviour of hGetLine.)
- [Sept 2002] Page 88, Section 7.1, Standard I/O functions.
Remove the paragraph "By default, these input functions echo to standard output."
(There was a lot of discussion on the Haskell mailing list on this point, in Sept 2002.
The conclusion was that the sentence should go, though it would have been better
to craft something more detailed.)
- Page 90, Section 7.3, Exception handling in the IO monad.
After the first paragraph give the following type signature:
userError :: String -> IOError
Also add an index entry for userError on this page.
(These changes are purely presentational.)
- [Apr 2001] Page 90, Section 7.3, Exception handling in the IO monad.
After the above signature for userError, add the following:
"The fail method of the IO instance of the Monad class (Section 6.3.6) raises a
userError, thus:
instance Monad IO where
...bindings for return, (>>=), (>>)
fail s = ioError (userError s)
"
- [Dec 2001] Page 91, Appendix A, Standard Prelude.
-
Add the following paragraph to clarify the status of the default-method definitions.
"The default method definitions, given with class declarations, constitute
a specification only of the default method. They do not constitute a
specification of the meaning of the method in all instances. To take
one particular example, the default method for enumFrom in class Enum
will not work properly for types whose range exceeds that of Int (because
fromEnum cannot map all values in the type to distinct Int values)."
- Add the following paragraph, to say why some functions have an unexpectedly
restricted type:
"To reduce the occurrence of unexpected ambiguity errors, and to
improve efficiency, a number of commonly-used functions over lists use
the Int type rather than using a more general numeric type, such as
Integral a or Num a. These functions are: take, drop,
index, length, splitAt, and replicate. The more general
versions are given in the List library, with the prefix
"generic"; for example genericLength."
- [Oct 2001] Page 93, Appendix A, Standard Prelude.
Replace the fixity declaration for (:) by the following comments:
-- The (:) operator is built-in syntax, and cannot legally be given
-- a fixtity declaration; but its fixity is given by:
-- infixr 5 :
- [Nov 2001] Page 94, Appendix A, Standard Prelude, class Enum.
- Before the default methods add:
-- NOTE: these default methods only make sense for types
-- that map injectively into Int using fromEnum
-- and toEnum.
-
After the default method for enumFromTo add
enumFromThen x y = map toEnum [fromEnum x, fromEnum y ..]
- Page 95, Appendix A, Standard Prelude, class Floating.
Add asin, acos, atan to the comment giving the list of minimal complete definitions.
- [Dec 2001] Page 100, Appendix A, instance Bounded Char.
(This avoids making explicit what the largest character is.)
- [Apr 2001] Page 101, Appendix A, instance Monad IO.
Replace the definition of fail in instance Monad IO by
fail s = ioError (userError s)
- Page 102, Appendix A, comments immediately before
instance Enum Float.
Replace "1.0" by "0.95".
- [Aug 2001] Page 101, Appendix A, instance of Monad IO.
Delete defintion for >> . (The default definition will do.)
- [Oct 2002] Page 103, Appendix A.1, line 19.
In the definition of numericFromThenTo replace "n' > n" by
"n' >= n". So the definition now reads:
numericEnumFromThenTo n n' m = takeWhile p (numericEnumFromThen n n')
where
p | n' >= n = (<= m + (n'-n)/2)
| otherwise = (>= m + (n'-n)/2)
(This change makes the code agree with the last bullet in (the revised version of) 6.3.4.)
- [Apr 2001] Page 105, Appendix A.1, line 11.
In the module header for PreludeList replace "Sum" by "sum".
- Page 105, Appendix A.1 (PreludeList), line 19.
Correct the type of map to
map :: (a -> b) -> [a] -> [b]
- Page 106, definition of (!!).
Replace the definition of (!!) with the following:
-- List index (subscript) operator, 0-origin
(!!) :: [a] -> Int -> a
xs !! n | n < 0 = error "Prelude.!!: negative index"
[] !! _ = error "Prelude.!!: index too large"
(x:_) !! 0 = x
(_:xs) !! n = xs !! (n-1)
(The original version had the property that ([] !! -100)
reported "index too large".)
- [Apr 2001] Page 107, definition of scanl1 and scanr1.
Replace the definitions of scanl1 and scanr1 with these:
scanl :: (a -> b -> a) -> a -> [b] -> [a]
scanl f q xs = q : (case xs of
[] -> []
x:xs -> scanl f (f q x) xs)
scanl1 :: (a -> a -> a) -> [a] -> [a]
scanl1 f (x:xs) = scanl f x xs
scanl1 _ [] = []
scanr1 :: (a -> a -> a) -> [a] -> [a]
scanr1 f [] = []
scanr1 f [x] = [x]
scanr1 f (x:xs) = f x q : qs
where qs@(q:_) = scanr1 f xs
The effect is to make both functions defined on the empty list.
- [Apr 2001] Page 108, definition of take, drop, and splitAt.
Replace the definitions of take, drop, and splitAt with these:
take :: Int -> [a] -> [a]
take n _ | n <= 0 = []
take _ [] = []
take n (x:xs) = x : take (n-1) xs
drop :: Int -> [a] -> [a]
drop n xs | n <= 0 = xs
drop _ [] = []
drop n (_:xs) = drop (n-1) xs
splitAt :: Int -> [a] -> ([a],[a])
splitAt n xs = (take n xs, drop n xs)
The effect is that all three functions are defined on negative arguments. This
is a semantic change.
- [Jan 2002] Page 112, header for PreludeText.
Remove show from the export list, and re-insert it as an exported
operation of class Show.
- [Nov 2001] Page 114, definition of lex.
Change the line that currently reads
lexFracExp s = [("",s)]
to read instead
lexFracExp s = lexExp s
(This change allows 10e3 to be a single lexeme; c.f. the lexical change on page 7.)
- [May 2001; showsPrec corrected Sept 2001]
Page 115, instances Show Int and Read Int.
Replace the instances for Show Int and Read Int with
instance Show Int where
showsPrec n = showsPrec n . toInteger
-- Converting to Integer avoids
-- possible difficulty with minInt
instance Read Int where
readsPrec p r = [(fromInteger i, t) | (i,t) <- readsPrec p r]
-- Reading at the Integer type avoids
-- possible difficulty with minInt
The previous definitions (which are simply specifications, remember) failed on minInt.
- [July 2002]
Page 115, instances Read Float and Read Double.
These two instance declarations should read:
instance Read Float where
readsPrec p = readSigned readFloat
instance Read Double where
readsPrec p = readSigned readFloat
(Adding the 'readSigned' call.)
- [Late Dec 2001] Page 118, defn of interact.
Replace the definition of interact with the following.
interact :: (String -> String) -> IO ()
-- The hSetBuffering ensures the expected interactive behaviour
interact f = do hSetBuffering stdin NoBuffering
hSetBuffering stdout NoBuffering
s <- getContents
putStr (f s)
- [Dec 2001] Page 122, Appendix B.3, Layout.
- Replace the first dashed item in the first bullet item by:
"If a let, where, do,, or of keyword is not followed by the lexeme {,
the token "{n}" is inserted after the keyword, where "n" is the indentation of the
next lexeme if there is one, or "0" if the end of file has been reached."
(This addresses the question of end of file just after a where.)
- Replace the third dashed item in the first bullet item by:
"Where the start of a token is preceded only by white space on
same line, this token is preceded by "<n>" where "n"
is the indentation of the token, provided that it is not,
as a consequence of the first two rules, preceded by "{n}".
(This addresses the question of empty lines (no layout token) and string-gap tokens
(no layout token in the middle of them). I have added a clarifying example as well.)
- [Nov 2001] Page 122, Appendix B.3, Layout.
In the paragraph following the bullets, add the sentence:
"The characters "newline", "return", "linefeed", and "formfeed", all start a new line."
- [Sept 2002] Page 122, Appendix B.3, Layout.
After the sentence "For the purposes of the layout rule, Unicode characters in a source program
are considered to be of the same, fixed, width as an ASCII character." add the clarifying sentence
"However, to avoid visual confusion, programmers should avoid writing programs in which
the meaning of implicit layout depends on the width of non-space characters."
- [Oct 2001] Page 123, Appendix B.3, Layout.
In the first line of the definition of L, replace "if parse-error(t)" by
"if m /= 0 and parse-error(t)". This checks that the implicitly-added close
brace matches an implicit open brace.
- [Late Dec 2001] Page 122,123, Appendix B.3, Layout.
-
On p122, replace "L tokens [0]" by "L tokens []".
-
Replace the layout equations on p123 with the following:
L (<n>:ts) (m:ms) | = | ; : (L ts (m:ms)) | if m = n |
| = | } : (L (<n>:ts) ms) | if n < m |
L (<n>:ts) ms | = | L ts ms |
|
L ({n}:ts) (m:ms) | = | { : (L ts (n:m:ms)) | if n > m (Note 1) |
L ({n}:ts) [] | = | { : (L ts [n]) | if n > 0 (Note 1) |
L ({n}:ts) ms | = | { : } : (L (<n>:ts) ms) | (Note 2) |
|
L (}:ts) (0:ms) | = | } : (L ts ms) | (Note 3) |
L (}:ts) ms | = | parse-error | (Note 3) |
|
L ({:ts) ms | = | { : (L ts (0:ms)) | (Note 4) |
|
L (t:ts) (m:ms) | = | } : (L (t:ts) ms) | if m /= 0 and parse-error(t) |
| | | (Note 5) |
L (t:ts) ms | = | t : (L ts ms) |
|
L [] [] | = | [] |
L [] (m:ms) | = | } : L [] ms | if m /=0 (Note 6)
|
- Renumber the notes correspondingly.
(These changes deal with various corner cases, such as empty where clauses;
order the equations so that they clearly deal completely with the tokens
"<n>", "{n}", "(", and "}" before dealing with the general case;
and ensure
that the tokens "<n>" and "{n}" are never passed to "parse-error".)
- [Aug 2001] Page 124, Appendix B.3, Layout.
Near the end of the sub-section, delete from "Another place where..." to the end of the
sub-section. (Note 5 covers the top-level case.)
- [May 2002] Page 124, Appendix B.3, Layout
To the very end of B.3, append the following:
"The parse-error rule is hard to implement in its full generality, because
doing so involves fixities. For example, the expression
do a == b == c
has a single unambiguous (albeit probably type-incorrect) parse, namely
(do { a == b }) == c
because (==) is non-associative. Programmers are therefore advised to avoid
writing code that requires the parser to insert a closing brace in such
situations."
- [Sept 2002] Page 130, Appendix C, Literate comments.
Move Appendix C (Literate comments) into Appendix B (Syntax), just after the section on Layout.
(This structure makes more sense when the report appears as a book.)
- [Oct 2001] Page 130, Appendix C, Literate comments.
In paragraph 2, replace
"The program text is recovered
by taking only those lines beginning with ">",
and deleting the first character of each of those lines"
with
"The program text is recovered
by taking only those lines beginning with ">",
and replacing the leading ">" with a space."
- [Late Dec 2001] Page 130, Appendix C, Literate comments.
Final paragraph. After the phrase "all other lines are comment." add the sentence:
"More precisely:
- Program code begins on the first line following a line that begins \begin{code}.
- Program code ends just before a subsequent line that begins \end{code} (ignoring
string literals, of course)."
- [May 2001] Page 132, Appendix D, Specification of Derived Instances.
In numbered item 3, replace
``(all constructors must by nullary)'' with
``(all constructors must be nullary)''.
- [Jan 2002] Page 132, Appendix D, Specification of Derived Instances.
Mention that computing the context for the derived instance declaration may involve
a fixpoint calculation.
- [Feb 2002, modified Oct 2002] Page 133, Appendix D.1, Derived Instances of Eq and Ord.
Add the final sentence:
All derived operations of class Eq and Ord are strict in both arguments.
For example, False <= _|_ is _|_ , even though False is the first constructor
of the Bool type.
- [Oct 2002] Page 134, Appendix D.4, Derived instances of Read and Show.
- In para 2, replace "10" by "11". Thus "(a number from 0 to 11)".
- In para 3 replace "...if d is 10 it is always surrounded
in parentheses, unless it is an atomic expression." by:
"if d is 11 it is always surrounded in parentheses, unless it is an
atomic expression (recall that function application has precedence 10)."
- [June 2001] Page 134, Appendix D.4, Derived instances of Read and Show.
In the displayed equation starting fst (head (...)) == x, replace "r" by
the empty string, resulting in the following:
(x,"") is an element of (readsPrec d (showsPrec d x ""))
(The old, stronger, equation is simply false.)
- [Oct 2002] Page 135, Appendix D.4, Derived instances of Read and Show.
In para 1, replace "readsPrec will parse any valid representation of the standard types
apart from lists, for
which only the bracketed form [...] is accepted." by:
"readsPrec will parse any valid representation of the standard types
apart from strings, for which only quoted strings are accepted, and other lists,
for which only the bracketed form [...] is accepted."
- [May 2002] Page 135, Appendix D.4, Derived instances of Read and Show.
Replace the paragraph starting "A precise description of the derived...", and all the following
bullets, with the following
(the main change is to make Show ignore associativity, so that
a simple derived parser will terminate even on left-recursive inputs):
The result of show is a syntactically correct Haskell expression
containing only constants, given the fixity declarations in force at
the point where the type is declared. It contains only the
constructor names defined in the data type, parentheses, and
spaces. When labelled constructor fields are used, braces, commas,
field names, and equal signs are also used. Parentheses
are only added where needed, ignoring associativity. No line breaks
are added. The result of show is readable by read if all component
types are readable. (This is true for all instances defined in the
Prelude but may not be true for user-defined instances.)
Derived instances of Read make the following assumptions,
which derived instances of Show obey:
- [Aug 2001] Page 138, Appendix E, Compiler pragmas.
(These changes simplify the pramga story, and bring it into line with what
is usually implemented.)
- [Apr 2001] Page 141, Bibliograpy.
Citation [4] should read "JR Hindley".
- Page 141, Bibliograpy.
The library report citation [8] is out of date. It should read:
"Simon Peyton Jones and John Hughes (editors), Standard Libraries for the
Haskell 98 Programming Language, 1 February 1999".
- Page 147, Index. Remove the entry for "monad comprehension".
- [Apr 2001] Index of the Haskell 98 Prelude (HTML version only)
- Remove Eval as a superclass of Num
- Correct type of seq to seq :: a -> b -> b.
- Correct type of getLine to IO String
- [Jan 2002] Correct type of map and add entry for fmap.
- [Jan 2002] Add entry for filter
- [Feb 2002] The equations given for foldl and foldr were wrong. They
should be
foldl (+) 0 [a,b,c] = ((0+a)+b)+c
foldr (+) 0 [a,b,c] = a+(b+(c+0))
Furthermore, the function name was misspelled in the equation for foldr1.
- Title page. Remove "[editor]" from after John Hughes.
- Title page. Add the paragraph:
"Copyright (c) Simon Peyton Jones.
The authors intend this Report to belong to the entire Haskell
community, and so we grant permission to copy and
distribute it for any purpose, provided that it is
reproduced in its entireity, including this Notice. Modified
versions of this Report may also be copied and distributed for any purpose,
provided that the modified version is clearly presented as such,
and that it does not claim to be a definition of the Haskell 98 libraries."
- [Apr 2001] Page 5, Section 2.1, Library Ratio.
Replace the definition of recip on line 3 by the following
recip (x:%y) = y % x
The effect of this change is to use the "smart constructor", %, instead
doing it by hand. In particular, an error will be raised if y is zero.
- [Oct 2002] Page 5, Section 2.1, Library Ratio.
Add the following definitions to the instance for Enum.
succ x = x+1
pred x = x-1
(This makes succ/pred behave in the same way for Ratio as they do for Float and Double.
Of course, it is still highly dubious having these fractional types in Enum at all,
but that is another matter.)
- [July 2002] Page 5, Section 2.1, Library Ratio.
Modify the Read and Show instances of Ratio as follows:
instance (Read a, Integral a) => Read (Ratio a) where
readsPrec p = readParen (p > prec)
(\r -> [(x%y,u) | (x,s) <- readsPrec (prec+1) r,
("%",t) <- lex s,
(y,u) <- readsPrec (prec+1) t ])
instance (Integral a) => Show (Ratio a) where
showsPrec p (x:%y) = showParen (p > prec)
(showsPrec (prec+1) x .
showString " % " .
showsPrec (prec+1) y)
(It is important that the recursive calls carry the appropriate precedence.)
- [Nov 2001] Page 9, Numeric library.
- Add showIntAtBase, showHex, and showOct to the export list.
- Add documentation for these functions.
- In the body of the module, replace the definition of showInt with the following:
showSigned :: Real a => (a -> ShowS) -> Int -> a -> ShowS
showSigned showPos p x
| x < 0 = showParen (p > 6) (showChar '-' . showPos (-x))
| otherwise = showPos x
-- showInt, showOct, showHex are used for positive numbers only
showInt, showOct, showHex :: Integral a => a -> ShowS
showOct = showIntAtBase 8 intToDigit
showInt = showIntAtBase 10 intToDigit
showHex = showIntAtBase 16 intToDigit
showIntAtBase :: Integral a
=> a -- base
-> (Int -> Char) -- digit to char
-> a -- number to show
-> ShowS
showIntAtBase base intToDig n rest
| n < 0 = error "Numeric.showIntAtBase: can't show negative numbers"
| n' == 0 = rest'
| otherwise = showIntAtBase base intToDig n' rest'
where
(n',d) = quotRem n base
rest' = intToDig (fromIntegral d) : rest
(This siginficant change extends the Numeric library so that it can show
octal and hexadecimal numbers, just as it can already read them.)
- [Nov 2001] Page 13, Section 4.1, Numeric library.
- Add specifications for the functions exported by the Numeric library.
- In formatRealFloat, replace the entire case alternative
starting FFFixed with the following:
FFFixed ->
case decs of
Nothing -- Always prints a decimal point
| e > 0 -> take e (ds ++ repeat '0')
++ '.' : mk0 (drop e ds)
| otherwise -> "0." ++ mk0 (replicate (-e) '0' ++ ds)
Just dec -> -- Print decimal point iff dec > 0
let dec' = max dec 0 in
if e >= 0 then
let (ei, is') = roundTo base (dec' + e) is
(ls, rs) = splitAt (e+ei)
(map intToDigit is')
in mk0 ls ++ mkdot0 rs
else
let (ei, is') = roundTo base dec'
(replicate (-e) 0 ++ is)
d : ds = map intToDigit
(if ei > 0 then is' else 0:is')
in d : mkdot0 ds
where
mk0 "" = "0" -- Print 0.34, not .34
mk0 s = s
mkdot0 "" = "" -- Print 34, not 34.
mkdot0 s = '.' : s -- when the format specifies no
-- digits after the decimal point
(This fixes an infinite loop.)
- In the definition of k in floatToDigits replace "fromInt e" by "fromIntegral e".
(fromInt no longer exists.)
- Last line of code for floatToDigits, replace "toInt" by "fromIntegral".
(toInt no longer exists.)
- [Sept 2001] Page 16, Section 4, Numeric library. In the definition
of readFloat, after "... (k,t) <- readExp s]" add
++ [ (0/0, t) | ("NaN",t) <- lex r]
++ [ (1/0, t) | ("Infinity",t) <- lex r]
(This makes readFloat able to read "Infinity" and "NaN", which formatRealFloat
can produce.)
- [May 2002] Page 9, Section 4, Numeric library. In the type for
readFloat replace "(RealFloat a)" by "(RealFrace a)".
(This makes it possible to read a Rational number using readFloat.)
- Page 17, Section 5, first text line. Replace "continuous" by "contiguous".
- [May 2001] Page 17, Section 5, Indexing operations.
Add the following equation to the laws listed just before Section 5.1:
map index (range (l,u)) == [0..rangeSize (l,u)]
This documents an invariant that was previously only implicit.
- [Oct 2001] Page 17, Section 5, Indexing operations.
This significant item makes rangeSize into a method of
Ix rather than a free-standing declaration. Though this
change is visible to the programmer, all existing Haskell 98
programs will continue to work.
- Page 17, Section 5, Indexing operations, boxed text.
Replace the Ix
class declaration, and the type signature for rangeSize with:
class Ord a => Ix a where
range :: (a,a) -> [a]
index :: (a,a) -> a -> Int
inRange :: (a,a) -> a -> Bool
rangeSize :: (a,a) -> Int
- Section 5.2, pages 19, line 3. Replace the Ix
class declaration, and the rangeSize declaration, with:
class Ord a => Ix a where
range :: (a,a) -> [a]
index :: (a,a) -> a -> Int
inRange :: (a,a) -> a -> Bool
rangeSize :: (a,a) -> Int
rangeSize b@(l,h) | null (range b) = 0
| otherwise = index b h + 1
-- NB: replacing "null (range b)" by "not (l <= h)"
-- fails if the bounds are tuples. For example,
-- (1,2) <= (2,1)
-- but the range is nevertheless empty
-- range ((1,2),(2,1)) = []
(Note: the comment has changed too; it was misleading before.)
(Note: an earlier proposal to remove the Ord superclass was rejected.)
- [July 2001] Page 17, Section 5.1, Derived instances of Ix.
Replace the first paragraph with the following:
"It is possible to derive an instance of Ix automatically, using
a deriving clause on a data declaration (Section 4.3.3
of the Language Report).
Such derived instance declarations for the class Ix are only possible
for enumerations (i.e. datatypes having
only nullary constructors) and single-constructor datatypes,
whose constituent types are instances of Ix. A Haskell implementation
must provide Ix instances for tuples up to at least size 15."
[This change just clarifies, and propagates the "instances up to size 15" change from
Section 6.1.6 of the Language Report.]
- Page 22, Section 6.3; and Page 23, Fig 3:
Replace "map" by "fmap" (two occurrences in 6.3, one in Fig 3).
- [Dec 2001] Page 23, Figure 3.
In the definition of diag, delete the guard ``| l==l' && u==u'''.
(The original intent was presumably to check for a square array, but
simply makes the definition recursive and hence divergent.)
- [July 2002] Page 24, Section 6.4, Library Array.
Use the following Read and Show instances for Array:
instance (Ix a, Show a, Show b) => Show (Array a b) where
showsPrec p a = showParen (p > arrPrec) (
showString "array " .
showsPrec (arrPrec+1) (bounds a) . showChar ' ' .
showsPrec (arrPrec+1) (assocs a) )
instance (Ix a, Read a, Read b) => Read (Array a b) where
readsPrec p = readParen (p > arrPrec)
(\r -> [ (array b as, u)
| ("array",s) <- lex r,
(b,t) <- readsPrec (arrPrec+1) s,
(as,u) <- readsPrec (arrPrec+1) t ])
-- Precedence of the 'array' function is that of application itself
arrPrec = 10
(It is important that the recursive calls use the appropriate precedence.)
- Page 29, Section 7.2. Add a new bullet for nub.
Add an index entry for nub.
- Page 29, Section 7.2, second bullet.
Introduce a new bullet just before "union is list union".
- [July 2002] Page 29, Section 7.2, third bullet.
Remove the first intersect in the displayed equation.
- Page 30, Section 7.3. Add a bullet for insert.
- [May 2001] Page 30, Section 7.4, unfoldr.
Replace the first line-and-a-half paragraph with:
"The unfoldr function is a `dual' to foldr: while foldr reduces a list
to a summary value, unfoldr builds a list from a seed value. For
example:
iterate f == unfoldr (\x -> Just (x, f x))
In some cases, unfoldr can undo a foldr operation:"
(Followed by the existing displayed equation.)
- [Feb 2002] Page 31, Section 7.6, The "By" operations.
Change the defintion of nub to:
nub :: (Eq a) => [a] -> [a]
nub [] = []
nub (x:xs) = x : nub (filter (\y -> not (x == y)) xs)
(This eliminates a conflict with the definition in Section 7.8.)
- [Apr 2001] Page 31, Section 7.7, Library List.
Add a new subsection "The zip operations" to document zip4, zip5, etc.
- [Dec 2001] Page 33, Section 7.8, Library List.
Replace the definition of unionBy by the following:
unionBy eq xs ys = xs ++ deleteFirstsBy eq (nubBy eq ys) xs
(This is a simpler definition to understand.)
- [Apr 2001] Page 34, Section 7.8, Library List.
Replace the definition of partition by
partition :: (a -> Bool) -> [a] -> ([a],[a])
partition p xs = (filter p xs, filter (not . p) xs)
This simply makes it agree with the definition on page 30 (Section 7.3).
- [Apr 2001] Page 35, Section 7.8.
Replace the definitions of maximumBy and minimumBy by the following
maximumBy :: (a -> a -> Ordering) -> [a] -> a
maximumBy cmp [] = error "List.maximumBy: empty list"
maximumBy cmp xs = foldl1 max xs
where
max x y = case cmp x y of
GT -> x
_ -> y
minimumBy :: (a -> a -> Ordering) -> [a] -> a
minimumBy cmp [] = error "List.minimumBy: empty list"
minimumBy cmp xs = foldl1 min xs
where
min x y = case cmp x y of
GT -> y
_ -> x
NOTE: this is a semantic change, but it makes the definitions
consistent with the other "By" functions, and with the signatures given on page 28.
- [Dec 2001] Page 41, Sections 9, Character utilities.
Add an explanation of lexLitChar, and an example.
- [Jan 2002] Page 43, Sections 9.1, Library Char.
Add isLatin1 to the list of variables in the type signature
for "character-testing operations".
- [May 2002] Page 45, Sections 9.1, Library Char.
Replace the first equation for lexLitChar with the following
lexLitChar ('\\':s) = map (prefix '\\') (lexEsc s)
where
lexEsc (c:s) | c `elem` "abfnrtv\\\"'" = [([c],s)]
lexEsc ('^':c:s) | c >= '@' && c <= '_' = [(['^',c],s)]
-- Numeric escapes
lexEsc ('o':s) = [prefix 'o' (span isOctDigit s)]
lexEsc ('x':s) = [prefix 'x' (span isHexDigit s)]
lexEsc s@(d:_) | isDigit d = [span isDigit s]
-- Very crude approximation to \XYZ.
lexEsc s@(c:_) | isUpper c = [span isCharName s]
lexEsc _ = []
isCharName c = isUpper c || isDigit c
prefix c (t,s) = (c:t, s)
(The effect is to allow octal and hexadecimal escapes in lexLitChar, just
as in readLitChar.)
- Page 48, Sections 10.3, Monads.
In the definition of listFile replace "openFile" by "readFile".
- Page 54, Sections 11, 12, 13.
Replace "isIllegalOperationError" with "isIllegalOperation" throughout.
Namely:
- Section 11.1, second para after bullets (two occurrences).
- Section 12, para 2 (two occurrences).
- Section 13, para 2 (two occurrences).
(It was inconsistent before.)
- Page 54, Section 11.
The signature for try should be
try :: IO a -> IO (Either IOError a)
- [May 2001] Page 57, Section 11.2.1 Semi-closed handles.
Replace the sentence "Once a semi-closed handle becomes closed..." with
"Once a semi-closed handle becomes closed, the contents of the
associated list becomes fixed. The contents of this final list is
only partially specified: it will contain at least all the items of
the stream that were evalutated prior to the handle becoming closed."
This change attempts to clarify the (murky) meaning of hGetContents followed by
hClose.
- [Apr 2001] Page 56-58, Section 11.2, Files and Handles.
Add a section 11.2.3 to clarify the file-locking issue. It says:
"Implementations should enforce as far as possible, at least locally to the
Haskell process, multiple-reader single-writer locking on files.
That is, there may either be many handles on the same file which manage
input, or just one handle on the file which manages output. If any
open or semi-closed handle is managing a file for output, no new
handle can be allocated for that file. If any open or semi-closed
handle is managing a file for input, new handles can only be allocated
if they do not manage output. Whether two files are the same is
implementation-dependent, but they should normally be the same if they
have the same absolute path name and neither has been renamed, for
example.
Warning: the readFile operation (Section 7.1 of the Haskell Language Report)
holds a semi-closed handle on the file until the entire contents of the file have been
consumed. It follows that an attempt to write to a file (using writeFile, for example)
that was earlier opened by readFile will usually result in
failure with isAlreadyInUseError."
- [Sept 2002] Page 58, Section 11.3.2 Closing Files.
Replace the sentence "If the operation fails for any reason ... successfully closed."
by
"Performing hClose on a handle that has already been closed has no effect;
doing so not an error. All other operations on a closed handle will fail.
If hClose fails for any reason, any further operations (apart from hClose) on the
handle will still fail as if "hdl" had been successfully closed."
(The significant change here is that it is not an error to hClose a handle twice.)
- [May 2001] Page 59, Section 11.4.2.
Before "The buffer is emptied as soon as it has been written out." add:
"An implementation is free to flush the buffer more frequently, but not
less frequently, than
specified above." (Clarification only.)
- [May 2001] Page 59, Section 11.4.2.
In the second no-buffering bullet (sixth bullet in the sub-section) add the
sentence: "The hLookAhead operation implies that
even a no-buffered handle may require a one-character buffer. " (Clarification only.)
- [May 2002] Page 60, Section 11.7.1, Checking for input.
- Page 62, Section 11.7.2.
- Add a new section heading "11.7.3 Reading the entire input"
just before the paragraph about hGetContents.
-
Add a new section heading "11.7.4 Text output" before the
paragraph about hPutChar.
- Page 63, definition of main in Section 11.8.1.
Replace the definition of "readNum" with
where readNum :: IO Integer
-- Need a type signature for readLn to avoid ambiguity
readNum = readLn
(This change merely advertises the generally useful function readLn.)
- Page 64, Section 12, Directory functions.
(More an editor's blunder than a typo.)
-
Replace the abstract definition of Permissions, and the four instances
of Permissions with
data Permissions
= Permissions {
readable, writable, executable, searchable :: Bool
}
deriving ( Eq, Ord, Read, Show )
- Remove readable, writable, executable, searchable both from
the module header, and from the module body.
- Change Permissions to Permissions(Permissions, readable, writable, executable, searchable)
in the module header.
- [Dec 2001] Page 65, Directory functions.
To paragraph 4, the "Error reporting" paragraph for createDirectory, append the
final clause "; or isDoesNotExistError if the new directory's parent does not exist".
- [Nov 2001] Page 66, Directory functions.
Add to the paragraph "Computation getDirectoryContents dir returns a list of all entries
in dir." the following extra sentence:
"Each entry in the returned list is named relative to the directory dir, not as an absolute path."
- [Dec 2002] Page 70, Section 14, The Time library; and page 72, section 14.1.
Add ctSec to the export list for Time (in two places).
- [Apr 2001] Page 78, Section 16, The CPUTime library.
Add cpuTimePrecision to the export list.
- [Apr 2001] Page 81, Section 17.1, The RandomGen class.
This sigificant semantic change adds a method genRange to the RandomGen
class. (Extensive discussion on the Haskell mailing list made it clear that this change
is essential to make the RandomGen class useful.) The following summarises the changes
but not in the detailed line-by-line form used for the rest of the errata.
- Add a method genRange :: g -> (Int,Int) to class RandomGen.
- Give it the default method genRange g = (minBound,maxBound)
- Add a specification of genRange
- Change the header on page 80 to match.
- [Apr 2001] Page 81, Section 17.1, The RandomGen class.
Specify more precisely that split must deliver independent generators.
- Page 81, Section 17.1, The RandomGen class.
Bottom line on page 81: replace "show/Read instances" with
"Show/Read instances" (i.e. capitalise Show).
- Page 83, Section 17.3, The global random number generator.
In the first paragraph, replace "kernal" by "kernel".