Add README
[haskell-report.git] / haskell98-bugs.html
1 <html>
2 <head>
3 </head>
4 <HEAD>
5 <TITLE>Haskell 98: ERRATA</title></head>
6 </head>
7 </head>
8 </head>
9 </head>
10 </HEAD>
11 <BODY>
12 <div align=center>
13 <img src="h98.gif" alt="Haskell 98">
14 </div>
15
16 <h1>Errata in the
17 <a href="http://haskell.cs.yale.edu/definition/">Haskell 98 Language Report</a></h1>
18
19 <ul>
20 <p><li> <strong>Title page</strong>. Add the paragraph:
21 <p>
22 "Copyright (c) Simon Peyton Jones and John Hughes.
23 <p>
24 The authors intend this Report to belong to the entire Haskell
25 community, and so we grant permission to copy and
26 distribute it for any purpose, provided that it is
27 reproduced in its entireity, including this Notice. Modified
28 versions of this Report may also be copied and distributed for any purpose,
29 provided that the modified version is clearly presented as such,
30 and that it does not claim to be a definition of the language Haskell 98."
31
32 <p><li> <strong>Page 9, Section 2.6, Character and String Literals.</strong>
33 In the production for "cntrl" replace "ASClarge" by "ascLarge".
34
35 <p><li> <strong>Page 10, Section 2.7, Layout.</strong>
36 In the middle of the third paragraph, just before the sentence beginning
37 "A close brace is also inserted...", add the following sentence:
38 <p>
39 "If the indentation of the non-brace lexeme immediately
40 following a <tt>where</tt>, <tt>let</tt>,
41 <tt>do</tt> or <tt>of</tt> is less than or equal to the <em>current</em> indentation level,
42 then instead of starting a layout, an empty list "<tt>{}</tt>" is inserted, and
43 layout processing occurs for the current level (i.e. insert a semicolon or close brace)."
44
45 <p><li> <strong>Page 11, Figures 1 and 2</strong>. In both figures the signature for <tt>size</tt>
46 should be
47 <pre>
48 size :: Stack a -> Int
49 </pre>
50
51 <p><li> [Apr 2001] <strong>Page 14, Section 3.1, Errors.</strong> In the first sentence of
52 the section, after "indistinguishable" add "by a Haskell program".
53
54 <p><li> [Apr 2001] <strong>Page 20, Section 3.10, Arithmetic sequences.</strong>
55 In the second paragraph, in the sentence "For the type <tt>Integer</tt>,
56 arithmetic sequences have the following meaning...", replace "<tt>Integer</tt>"
57 with "<tt>Int</tt>".
58
59 <p><li> [Apr 2001] <strong>Page 21, Section 3.11, List Comprehensions; and Page 128.</strong>
60 <ul> <li> In the production for "aexp", change the "n >= 0" to "n >= 1".
61 <li> Remove the production for (empty qualifier)
62 <li> In the translation box lower down the page, rewrite the translation so
63 that it does not involve and empty list of qualifiers. (Unchanged semantics.)
64 </ul>
65 This change ensures that there is at least one qualifier in list comprehension,
66 and no qualifier is empty. The translation lower down page 23 is then
67 not utterly rigorous, because Q can be empty, and when it is there is no preceding
68 comma, but I reckon it would make matters worse to "fix" it.
69
70 <p><li> [Apr 2001] <strong>Page 23, Section 3.14, Do Expressions;
71 and Page 128, Appendix B.4, Context Free Syntax.</strong>
72 <ul>
73 <li>
74 Change the production for <em>stmts</em> to read:
75 <pre>
76 stmts -> stmt1 ... stmtn exp [;] (n>=0)
77 </pre>
78 <li> Add "<tt>;</tt>" to the end of each of the four productions for <em>stmt</em>.
79 </ul>
80 That is, every list of statements must end in an expression, optionally
81 followed by a semicolon.
82
83 <p><li> [Apr 2001] <strong>Page 31,33, Figures 3 and 4, Semantics of Case Expressions.</strong>
84 Replace "completely new variable" by "new variable" in these two figures. (Some clauses
85 said "new" and some "completely new" which is misleadingly inconsistent.)
86
87 <p><li> [Apr 2001] <strong>Page 33, Figure 4, Semantics of Case Expressions Part 2.</strong>
88 In clause (r) replace "e0" by "v" throughout.
89
90 <p><li> <strong>Page 40, Section 4.2.1, Algebraic Datatype Declarations.</strong>
91 In the bottom paragraph on the page, before "The context in the data declaration
92 has no other effect whatsoever" add the following:
93 <p>
94 "Pattern matching against <tt>ConsSet</tt> also gives rise to an <tt>Eq a</tt>
95 constraint. For example:
96 <pre>
97 f (ConsSet a s) = a
98 </pre>
99 the function <tt>f</tt> has inferred type <tt>Eq a => Set a -> a</tt>."
100
101 <p><li> <strong>Page 41, Section 4.2.1, subsection Labelled Fields.</strong>
102 At the end of the subsection, add a new paragraph:
103 <p>
104 "The pattern "<tt>F {}</tt>" matches any value built with constructor <tt>F</tt>,
105 <em>whether or not <tt>F</tt> was declared with record syntax</em>."
106
107 <p><li> [Apr 2001] <strong>Page 42, Section 4.2.1, subsection Labelled Fields.</strong>
108 Change "occurance" to "occurrence" in the translation box at the very end of
109 the section.
110
111 <p><li> <strong>Page 49, Section 4.3.4, Ambiguous Types...</strong>
112 In the third paragraph from the end of Section 4.3.4, replace "...an ambiguous
113 type variable is defaultable if at least one of its classes is a numeric class..."
114 by "...an ambiguous type variable, v, is defaultable if v appears only in constraints
115 of the form (C v), where C is a class, and if at least one of its classes is
116 a numeric class...".
117 <p>
118 The new phrase is "if v appears only in constraints of the
119 form (C v) where C is a class". Without this condition the rest of the
120 sentence does not make sense.
121
122 <p><li> [Apr 2001] <strong>Page 53, Section 4.3.3.</strong> Replace "For example, these two function
123 definitions are equivalent:", and the two lines of code that follow by:
124 <br>
125 "For example, these three function definitions are all equivalent:
126 <pre>
127 plus x y z = x+y+z
128 x `plus` y = \ z -> x+y+z
129 (x `plus` y) z = x+y+z
130 </pre>"
131 (This change makes explicit that an infix operator with more than two arguments
132 can have all of them on the LHS.)
133
134 <p><li> [Apr 2001] <strong>Page 54, Section 4.4.3, subsection Function Bindings.</strong>
135 In the first translation scheme ("The general binding form for functions..."),
136 the <em>xn</em> should be <em>xk</em> (suitably subscripted in both cases!),
137 and all three <em>m</em> subscripts should be <em>n</em>.
138
139 <p><li> <strong>Page 57, Section 4.5.3, Context reduction errors.</strong>
140 The example
141 <pre>
142 f :: (Monad m, Eq (m a)) => a -> m a -> Bool
143 f x y = x == return y
144 </pre>
145 is wrong; it should read
146 <pre>
147 f x y = return x == y
148 </pre>
149
150 <p><li> [May 2001] <strong>Page 62, Section 5, Modules.</strong>
151 In paragraph 4, add a footnote to the sentence "A multi-module Haskell
152 program can be converted into a single-module program by ...", namely:
153 <p>
154 "There are two minor exceptions to this statement.
155 First, <tt>default</tt> declarations scope over a single module (Section 4.3.4).
156 Second, Rule 2 of the monomorphism restriction (Section 4.5.5)
157 is affected by module boundaries."
158 <p>
159 This footnote qualifies the otherwise over-strong statement.
160
161 <p><li> <strong>Page 66, Section 5.3, Import Declarations, numbered item 2.</strong>
162 Start a new paragraph before the sentence "The hiding clause only applies to unqualified
163 names...".
164
165 <p><li><strong>Page 67, Section 5.3.2, Local aliases</strong>.
166 The the last example in the section should read:
167 <pre>
168 import Foo as A(f)
169 </pre>
170
171 <p><li> <strong>Page 69, Section 5.5.2, Name clashes.</strong>
172 At the very end of the section, add the following clarification:
173 <p>
174 "The name occurring in a type signature or fixity declarations is always
175 unqualified, and unambiguously refers to another declaration in the
176 same declaration list (except that the fixity declaration for a class method
177 can occur at top level --- Section 4.4.2). For example, the following
178 module is legal:
179 <pre>
180 module F where
181 sin :: Float -> Float
182 sin x = (x::Float)
183
184 f x = Prelude.sin (F.sin x)
185 </pre>
186 The local declaration for <tt>sin</tt> is legal, even though
187 the <tt>Prelude</tt> function <tt>sin</tt> is implicitly in scope.
188 The references to
189 <tt>Prelude.sin</tt> and <tt>F.sin</tt> must both be qualified to make
190 it unambigous which <tt>sin</tt> is meant.
191 However, the unqualified name "<tt>sin</tt>" in the type
192 signature in the first line of <tt>F</tt> unambiguously refers to the
193 local declaration for <tt>sin</tt>."
194
195 <p><li> <strong>Page 71, Section 5.6.2, Shadowing Prelude Names.</strong>
196 Replace the example at the beginning of the section, and the entire
197 following paragraph, with the following
198 "<pre>
199 module A( null, nonNull ) where
200 import Prelude hiding( null )
201 null, nonNull :: Int -> Bool
202 null x = x == 0
203 nonNull x = not (null x)
204 </pre>
205 Module <tt>A</tt> redefines <tt>null</tt>, and contains an unqualified reference
206 to <tt>null</tt> on the right hand side of <tt>nonNull</tt>.
207 The latter would be ambiguous without the "<tt>hiding(null)</tt>" on the
208 "<tt>import Prelude</tt>" statement.
209 Every module that imports <tt>A</tt> unqualified, and then makes an unqualified
210 reference to <tt>null</tt> must also resolve the ambiguous use of <tt>null</tt>
211 just as <tt>A</tt> does. Thus there is little danger of accidentally shadowing
212 Prelude names."
213
214 <p><li> [May 2001] <strong>Page 74, Section 6.1.6, Tuples.</strong>
215 Replace the first paragraph of this section with:
216 <p>
217 "Tuples are algebraic datatypes with special syntax, as defined
218 in Section 3.8. Each tuple type has a single constructor.
219 All tuples are instances of <tt>Eq</tt>, <tt>Ord</tt>, <tt>Bounded</tt>, <tt>Read</tt>,
220 <tt>Show</tt>, and <tt>Ix</tt> (provided, of course, that all their component types are).
221 <p>
222 There is no upper bound on the size of a tuple, but some Haskell
223 implementations may restrict the size of tuples, and limit the
224 instances associated with larger tuples. However, every Haskell
225 implementation must support tuples up to size 15, together with their instances
226 for <tt>Eq</tt>, <tt>Ord</tt>, <tt>Bounded</tt>, <tt>Read</tt>,
227 <tt>Show</tt>, and <tt>Ix</tt>. The Prelude and
228 libraries define tuple functions such as <tt>zip</tt> for tuples up to a size
229 of 7."
230
231
232 <p><li> [Apr 2001] <strong>Page 74, Section 6.1.6, Function Types.</strong>
233 Delete the sentence "Functions are an instance of the <tt>Show</tt> class but not <tt>Read</tt>".
234
235 <p><li> [Apr 2001] <strong>Page 76, Section 6.3, Standard Haskell classes.</strong>
236 There is a formatting error in the example. There should be a new line
237 after "the declaration of Class Eq is:", and before the sentence beginning
238 "This declaration gives default method declarations...".
239
240 <p><li> [Apr 2001] <strong>Page 78, Section 6.3.3, The Read and Show Classes.</strong>
241 After "The <tt>Read</tt> and <tt>Show</tt> classes are used to convert values
242 to and from strings." add the sentence:
243 "The <tt>Int</tt> argument to <tt>showsPrec</tt> and <tt>readsPrec</tt> gives the operator
244 precedence of the enclosing context (see Appendix D.4)."
245 (Clarification only.)
246
247 <p><li><strong>Page 80, Section 6.3.6, Class Monad.</strong>
248 Right at the bottom of the page, replace "However, for IO, the fail
249 method invokes error." by "For IO, the fail method raises a user
250 exception in the IO monad (see Section 7.3)."
251
252 <p><li> [Apr 2001] <strong>Page 84, Section 6.4, Fig 7; and bottom of page 86, Section 6.4.6.</strong>
253 <pre>
254 fromRealFrac :: (RealFrac a, Fractional b) => a -> b
255 </pre>
256 should be replaced by
257 <pre>
258 realToFrac :: (Real a, Fractional b) => a -> b
259 </pre>
260
261 <p><li><strong>Page 90, Section 7.3, Exception handling in the IO monad.</strong>
262 After the first paragraph give the following type signature:
263 <pre>
264 userError :: String -> IOError
265 </pre>
266 Also add an index entry for <tt>userError</tt> on this page.
267 (These changes are purely presentational.)
268
269 <p><li> [Apr 2001] <strong>Page 90, Section 7.3, Exception handling in the IO monad.</strong>
270 After the above signature for <tt>userError</tt>, add the following:
271 "The <tt>fail</tt> method of the <tt>IO</tt> instance of the <tt>Monad</tt> class (Section 6.3.6) raises a
272 <tt>userError</tt>, thus:
273 <pre>
274 instance Monad IO where
275 ...bindings for return, (>>=), (>>)
276
277 fail s = ioError (userError s)
278 </pre>"
279
280 <p><li><strong>Page 94, Appendix A, Standard Prelude, class <tt>Enum</tt>.</strong>
281 After the default method for <tt>enumFromTo</tt> add
282 <pre>
283 enumFromThen x y = map toEnum [fromEnum x, fromEnum y ..]
284 </pre>
285
286 <p><li> [Apr 2001] <strong>Page 101, Appendix A, <tt>instance Monad IO</tt>.</strong>
287 Replace the definition of <tt>fail</tt> in <tt>instance Monad IO</tt> by
288 <pre>
289 fail s = ioError (userError s)
290 </pre>
291
292 <p><li><strong>Page 102, Appendix A, comments immediately before
293 <tt>instance Enum Float</tt>.</strong>
294 Replace "<tt>1.0</tt>" by "<tt>0.95</tt>".
295
296 <p> <li> [Apr 2001] <strong>Page 105, Appendix A.1, line 11.</strong>
297 In the module header for <tt>PreludeList</tt> replace "<tt>Sum</tt>" by "<tt>sum</tt>".
298
299 <p><li><strong>Page 105, Appendix A.1 (PreludeList), line 19.</strong>
300 Correct the type of <tt>map</tt> to
301 <pre>
302 map :: (a -> b) -> [a] -> [b]
303 </pre>
304
305 <p><li><strong>Page 106, definition of <tt>(!!)</tt>.</strong>
306 Replace the definition of <tt>(!!)</tt> with the following:
307 <pre>
308 -- List index (subscript) operator, 0-origin
309 (!!) :: [a] -> Int -> a
310 xs !! n | n < 0 = error "Prelude.!!: negative index"
311 [] !! _ = error "Prelude.!!: index too large"
312 (x:_) !! 0 = x
313 (_:xs) !! n = xs !! (n-1)
314 </pre>
315 (The original version had the property that <tt>([] !! -100)</tt>
316 reported "index too large".)
317
318 <p><li> [Apr 2001] <strong>Page 107, definition of <tt>scanl1</tt> and <tt>scanr1</tt>.</strong>
319 Replace the definitions of <tt>scanl1</tt> and <tt>scanr1</tt> with these:
320 <pre>
321 scanl :: (a -> b -> a) -> a -> [b] -> [a]
322 scanl f q xs = q : (case xs of
323 [] -> []
324 x:xs -> scanl f (f q x) xs)
325
326 scanl1 :: (a -> a -> a) -> [a] -> [a]
327 scanl1 f (x:xs) = scanl f x xs
328 scanl1 _ [] = []
329
330 scanr1 :: (a -> a -> a) -> [a] -> [a]
331 scanr1 f [] = []
332 scanr1 f [x] = [x]
333 scanr1 f (x:xs) = f x q : qs
334 where qs@(q:_) = scanr1 f xs
335 </pre>
336 The effect is to make both functions defined on the empty list.
337
338
339 <p><li> [Apr 2001] <strong>Page 108, definition of <tt>take</tt>, <tt>drop</tt>, and <tt>splitAt</tt>.</strong>
340 Replace the definitions of <tt>take</tt>, <tt>drop</tt>, and <tt>splitAt</tt> with these:
341 <pre>
342 take :: Int -> [a] -> [a]
343 take n _ | n <= 0 = []
344 take _ [] = []
345 take n (x:xs) = x : take (n-1) xs
346
347 drop :: Int -> [a] -> [a]
348 drop n xs | n <= 0 = xs
349 drop _ [] = []
350 drop n (_:xs) = drop (n-1) xs
351
352 splitAt :: Int -> [a] -> ([a],[a])
353 splitAt n xs = (take n xs, drop n xs)
354 </pre>
355 The effect is that all three functions are defined on negative arguments. This
356 is a semantic change.
357
358 <p><li> [May 2001] <strong>Page 115, instances <tt>Show Int</tt> and <tt>Read Int</tt></strong>.
359 Replace the instances for <tt>Show Int</tt> and <tt>Read Int</tt> with
360 <pre>
361 instance Show Int where
362 showsPrec = showsPrec . toInteger
363 -- Converting to Integer avoids
364 -- possible difficulty with minInt
365
366 instance Read Int where
367 readsPrec p r = [(fromInteger i, t) | (i,t) <- readsPrec p r]
368 -- Reading at the Integer type avoids
369 -- possible difficulty with minInt
370 </pre>
371 The previous definitions (which are simply specifications, remember) failed on minInt.
372
373 <p><li> [May 2001] <strong>Page 132, Appendix D, Specification of Derived Instances</strong>.
374 In numbered item 3, replace
375 ``(all constructors must by nullary)'' with
376 ``(all constructors must be nullary)''.
377
378 <p><li> [June 2001] <strong>Page 134, Appendix D.4, Derived instances of Read and Show</strong>.
379 In the displayed equation starting <tt>fst (head (...)) == x</tt>, replace "<tt>r</tt>" by
380 the empty string, resulting in the following:
381 <pre>
382 fst (head (readsPrec d (showsPrec d x ""))) == x
383 </pre>
384 (The old, stronger, equation is simply false.)
385
386 <p><li> [Apr 2001] <strong>Page 141, Bibliograpy</strong>.
387 Citation [4] should read "JR Hindley".
388
389 <p><li> <strong>Page 141, Bibliograpy</strong>.
390 The library report citation [8] is out of date. It should read:
391 "Simon Peyton Jones and John Hughes (editors), Standard Libraries for the
392 Haskell 98 Programming Language, 1 February 1999".
393
394 <p><li><strong>Page 147, Index</strong>. Remove the entry for "monad comprehension".
395
396 <p><li> [Apr 2001] <strong>Index of the Haskell 98 Prelude (HTML version only)</strong>
397 <ul>
398 <li> Remove <tt>Eval</tt> as a superclass of <tt>Num</tt>
399 <li> Correct type of <tt>seq</tt> to <tt>seq :: a -> b -> b</tt>.
400 </ul>
401 </ul>
402
403 <hr>
404 <h1>Errata in the
405 <a href="http://haskell.cs.yale.edu/definition/">Haskell 98 Library Report</a></h1>
406
407 <ul>
408 <p><li> <strong>Title page</strong>. Add the paragraph:
409 <p>
410 "Copyright (c) Simon Peyton Jones and John Hughes.
411 <p>
412 The authors intend this Report to belong to the entire Haskell
413 community, and so we grant permission to copy and
414 distribute it for any purpose, provided that it is
415 reproduced in its entireity, including this Notice. Modified
416 versions of this Report may also be copied and distributed for any purpose,
417 provided that the modified version is clearly presented as such,
418 and that it does not claim to be a definition of the Haskell 98 libraries."
419
420 <p><li> [Apr 2001] <strong>Page 5, Section 2.1, Library <tt>Ratio</tt></strong>.
421 Replace the definition of <tt>recip</tt> on line 3 by the following
422 <pre>
423 recip (x:%y) = y % x
424 </pre>
425 The effect of this change is to use the "smart constructor", <tt>%</tt>, instead
426 doing it by hand. In particular, an error will be raised if y is zero.
427
428 <p><li> <strong>Page 17, Section 5, first text line</strong>. Replace "continuous" by "contiguous".
429
430 <p><li> [May 2001] <strong>Page 17, Section 5, Indexing operations</strong>.
431 Add the following equation to the laws listed just before Section 5.1:
432 <pre>
433 map index (range (l,u)) == [0..rangeSize (l,u)]
434 </pre>
435 This documents an invariant that was previously only implicit.
436
437 <p><li> [May 2001] <strong>Page 17, Section 5, Indexing operations</strong>.
438 This significant item (a) removes <tt>Ord</tt> from <tt>Ix</tt>'s superclasses, and
439 (b) make <tt>rangeSize</tt> into a method of <tt>Ix</tt> rather than a free-standing declaration.
440 Though these changes are
441 visible to the programmer, all existing Haskell 98 programs will continue to work.
442 <ul>
443 <li> <strong>Page 17, Section 5, Indexing operations, boxed text</strong>. Replace the <tt>Ix</tt>
444 change the class declaration, and the type signature for <tt>rangeSize</tt> with:
445 <pre>
446 class Ix a where
447 range :: (a,a) -> [a]
448 index :: (a,a) -> a -> Int
449 inRange :: (a,a) -> a -> Bool
450 rangeSize :: (a,a) -> Int
451 </pre>
452 <li> <strong>Section 5.2, pages 19, line 3</strong>. Replace the <tt>Ix</tt>
453 class declaration, and the <tt>rangeSize</tt> declaration, with:
454 <pre>
455 class Ix a where
456 range :: (a,a) -> [a]
457 index :: (a,a) -> a -> Int
458 inRange :: (a,a) -> a -> Bool
459 rangeSize :: (a,a) -> Int
460
461 rangeSize b@(l,h) | null (range b) = 0
462 | otherwise = index b h + 1
463 -- NB: replacing "null (range b)" by "not (l <= h)"
464 -- fails if the bounds are tuples. For example,
465 -- (1,2) <= (2,1)
466 -- but the range is nevertheless empty
467 -- range ((1,2),(2,1)) = []
468 </pre>
469 (Note: the comment has changed too; it was misleading before.)
470 </ul>
471
472 <p><li> [May 2001] <strong>Page 24, Section 6.6</strong>.
473 Add <tt>Eq a</tt> to the context for <tt>instance Eq (Array a b)</tt>, thus:
474 <pre>
475 instance (Ix a, Eq a, Eq b) => Eq (Array a b) ...
476 </pre>
477 Similarly, add <tt>Ord a</tt> to the context for <tt>instance Ord (Array a b)</tt>, thus:
478 <pre>
479 instance (Ix a, Ord a, Ord b) => Ord (Array a b) ...
480 </pre>
481 (Both consequences of removing <tt>Ord</tt> as a superclass of <tt>Ix</tt>.)
482
483 <p><li> <strong>Page 22, Section 6.3; and Page 23, Fig 3</strong>:
484 Replace "<tt>map</tt>" by "<tt>fmap</tt>" (two occurrences in 6.3, one in Fig 3).
485
486 <p><li> [May 2001] <strong>Page 23, Figure 3</strong>.
487 In the definition of <tt>diag</tt>, delete the guard ``<tt>| l==l' &amp;&amp; u==u'</tt>''.
488 (The original intent was presumably to check for a square array, but
489 simply makes the definition recursive and hence divergent.)
490
491 <p><li> <strong>Page 29, Section 7.2</strong>. Add a new bullet for <tt>nub</tt>.
492 Add an index entry for <tt>nub</tt>.
493
494 <p><li> <strong>Page 29, Section 7.2, second bullet</strong>.
495 Introduce a new bullet just before "<tt>union</tt> is list union".
496
497 <p><li> [May 2001] <strong>Page 30, Section 7.4, unfoldr</strong>.
498 Replace the first line-and-a-half paragraph with:
499 <p>
500 "The <tt>unfoldr</tt> function is a `dual' to <tt>foldr</tt>: while <tt>foldr</tt> reduces a list
501 to a summary value, <tt>unfoldr</tt> builds a list from a seed value. For
502 example:
503 <pre>
504 iterate f == unfoldr (\x -> Just (x, f x))
505 </pre>
506 In some cases, <tt>unfoldr</tt> can undo a <tt>foldr</tt> operation:"
507 <p>
508 (Followed by the existing displayed equation.)
509
510 <p><li> [Apr 2001] <strong>Page 34, Section 7.8, Library List</strong>.
511 Replace the definition of <tt>partition</tt> by
512 <pre>
513 partition :: (a -> Bool) -> [a] -> ([a],[a])
514 partition p xs = (filter p xs, filter (not . p) xs)
515 </pre>
516 This simply makes it agree with the definition on page 30 (Section 7.3).
517
518 <p><li> [Apr 2001] <strong>Page 35, Section 7.8</strong>.
519 Replace the definitions of <tt>maximumBy</tt> and <tt>minimumBy</tt> by the following
520 <pre>
521 maximumBy :: (a -> a -> Ordering) -> [a] -> a
522 maximumBy cmp [] = error "List.maximumBy: empty list"
523 maximumBy cmp xs = foldl1 max xs
524 where
525 max x y = case cmp x y of
526 GT -> x
527 _ -> y
528
529 minimumBy :: (a -> a -> Ordering) -> [a] -> a
530 minimumBy cmp [] = error "List.minimumBy: empty list"
531 minimumBy cmp xs = foldl1 min xs
532 where
533 min x y = case cmp x y of
534 GT -> y
535 _ -> x
536 </pre>
537 <strong>NOTE:</strong> this is a semantic change, but it makes the definitions
538 consistent with the other "By" functions, and with the signatures given on page 28.
539
540 <p><li><strong>Page 54, Section 11</strong>.
541 The signature for <tt>try</tt> should be
542 <pre>
543 try :: IO a -> IO (Either IOError a)
544 </pre>
545
546 <p><li> [May 2001] <strong>Page 57, Section 11.2.1 Semi-closed handles</strong>.
547 Replace the sentence "Once a semi-closed handle becomes closed..." with
548 "Once a semi-closed handle becomes closed, the contents of the
549 associated list becomes fixed. The contents of this final list is
550 only partially specified: it will contain at least all the items of
551 the stream that were evalutated prior to the handle becoming closed."
552 <p>
553 This change attempts to clarify the (murky) meaning of <tt>hGetContents</tt> followed by
554 <tt>hClose</tt>.
555
556 <p><li> [Apr 2001] <strong>Page 56-58, Section 11.2, Files and Handles</strong>.
557 Add a section 11.2.3 to clarify the file-locking issue. It says:
558 <p>
559 "Implementations should enforce as far as possible, locally to the
560 Haskell process, multiple-reader single-writer locking on files.
561 That is, there may either be many handles on the same file which manage
562 input, or just one handle on the file which manages output. If any
563 open or semi-closed handle is managing a file for output, no new
564 handle can be allocated for that file. If any open or semi-closed
565 handle is managing a file for input, new handles can only be allocated
566 if they do not manage output. Whether two files are the same is
567 implementation-dependent, but they should normally be the same if they
568 have the same absolute path name and neither has been renamed, for
569 example.
570
571 Warning: the <tt>readFile</tt> operation (Section 7.1 of the Haskell Language Report)
572 holds a semi-closed handle on the file until the entire contents of the file have been
573 consumed. It follows that an attempt to write to a file (using <tt>writeFile</tt>, for example)
574 that was earlier opened by <tt>readFile</tt> will usually result in
575 failure with <tt>isAlreadyInUseError</tt>."
576
577 <p><li> [May 2001] <strong>Page 59, Section 11.4.2</strong>.
578 Before "The buffer is emptied as soon as it has been written out." add:
579 "An implementation is free to flush the buffer more frequently, but not
580 less frequently, than
581 specified above." (Clarification only.)
582
583 <p><li> [May 2001] <strong>Page 59, Section 11.4.2</strong>.
584 In the second no-buffering bullet (sixth bullet in the sub-section) add the
585 sentence: "The <tt>hLookAhead</tt> operation implies that
586 even a no-buffered handle may require a one-character buffer. " (Clarification only.)
587
588 <p><li><strong>Page 62, Section 11.7.2</strong>.
589 <ul>
590 <li>Add a new section heading "<strong>11.7.3 Reading the entire input</strong>"
591 just before the paragraph about <tt>hGetContents</tt>.
592 <li>
593 Add a new section heading "<strong>11.7.4 Text output</strong>" before the
594 paragraph about <tt>hPutChar</tt>.
595 </ul>
596 <p><li><strong>Page 63, definition of <tt>main</tt> in Section 11.8.1</strong>.
597 Replace the definition of "<tt>readNum</tt>" with
598 <pre>
599 where readNum :: IO Integer
600 -- Need a type signature for readLn to avoid ambiguity
601 readNum = readLn
602 </pre>
603 (This change merely advertises the generally useful function <tt>readLn</tt>.)
604
605
606 <p><li><strong>Page 64, Section 12, Directory functions.</strong>
607 (More an editor's blunder than a typo.)
608 <ul>
609 <li>
610 Replace the abstract definition of <tt>Permissions</tt>, and the four instances
611 of <tt>Permissions</tt> with
612 <pre>
613 data Permissions
614 = Permissions {
615 readable, writable, executable, searchable :: Bool
616 }
617 deriving ( Eq, Ord, Read, Show )
618 </pre>
619 <li> Remove <tt>readable, writable, executable, searchable</tt> both from
620 the module header, and from the module body.
621 <li> Change <tt>Permissions</tt> to <tt>Permissions(readable, writable, executable, searchable)</tt>
622 in the module header.
623 </ul>
624
625 <p><li> [Apr 2001] <strong>Page 78, Section 16, The <tt>CPUTime</tt> library</strong>.
626 Add <tt>cpuTimePrecision</tt> to the export list.
627
628 <p><li>[Apr 2001] <strong>Page 81, Section 17.1, The <tt>RandomGen</tt> class</strong>.
629 This sigificant semantic change adds a method <tt>genRange</tt> to the <tt>RandomGen</tt>
630 class. (Extensive discussion on the Haskell mailing list made it clear that this change
631 is essential to make the RandomGen class useful.) The following summarises the changes
632 but not in the detailed line-by-line form used for the rest of the errata.
633 <ul>
634 <li> Add a method <tt>genRange :: g -> (Int,Int)</tt> to class <tt>RandomGen</tt>.
635 <li> Give it the default method <tt>genRange g = (minBound,maxBound)</tt>
636 <li> Add a specification of <tt>genRange</tt>
637 <li> Change the header on page 80 to match.
638 </ul>
639
640 <p><li>[Apr 2001] <strong>Page 81, Section 17.1, The <tt>RandomGen</tt> class</strong>.
641 Specify more precisely that <tt>split</tt> must deliver <strong>independent</strong> generators.
642
643 <p><li><strong>Page 81, Section 17.1, The <tt>RandomGen</tt> class</strong>.
644 Bottom line on page 81: replace "<tt>show/Read</tt> instances" with
645 "<tt>Show/Read</tt> instances" (i.e. capitalise <tt>Show</tt>).
646
647 <p><li><strong>Page 83, Section 17.3, The global random number generator</strong>.
648 In the first paragraph, replace "kernal" by "kernel".
649
650 </ul>
651 <hr>
652 <address>Simon Peyton Jones, simonpj@microsoft.com</address>
653 </body>
654 </html>
655