# Errata in ML for the Working Programmer, 2nd Edition

## Chapter 1

12, information box: (Dwight VandenBerghe) Milner's book is now in a new edition. Replace 1990 by 1997.

13, line -1: The last sentence may become out of date. (The book Standard ML Basis Library, edited by Gansner and Reppy, finally appeared in 2004.)

14, line 7: replace "contents are specified" by "contents are specified"

## Chapter 2

22, line -14: delete "the" before "booleans"

23, lines 9-10: (Dwight VandenBerghe) omit spaces around "area"

61, structure Complex (Randy Latimer): the function recip requires the type constraint ": real" somewhere. Otherwise, SML/NJ is unable to resolve the overloading and reports a type error.

67, line 1: (Tobias Nipkow) The remark about Damas and Milner (1982) is misleading: this paper outlines the framework for proving that types are principal. The proof itself may be found in Damas's 1985 PhD thesis from Edinburgh University.

## Chapter 3

91, function delrow. Replace p = hd row by Real.==(p,hd how). (The equality test on reals has become illegal in the past few years. The Basis Library now provides the function Real.== for the equality test.)

93, near bottom (Spyros Sarigiannidis). Replace "the form (u,y) for u<x" by "the form (u,y) for u≤x" (less-than or equals).

104, bottom (Nancy Rettew, via Marco Valtorta). Function depth is incorrect. The rev visited in the first pattern produces incorrect answers because it reverses the results of the inner calls too. (The previous function, depthf, is OK because it has no inner calls, and later functions do not reverse their result.) Change the first line to

`    fun depth ([], graph, visited) = visited `

and reverse its final result using an explicit call to rev:

`    rev (depth (["a"], graph1, []));`

117, line 12: replace the test a+b=0.0 by Real.==(a+b,0.0). (See the note above for page 91.)

118, line -8 (Spyros Sarigiannidis): replace "252.0x^5+" by "252.0x^5 +" (insert a space).

## Chapter 4

133, line -13 (Stephen Arons): Delete "as keyword@as keyword" . (It is indexing information.)

139, line -13 (Claus-Peter Wirth): In the first call to backChange, delete the first agument, namely []. (This function only accepts two arguments.)

144, line 5 (Spyros Sarigiannidis): Replace 2n by 2n-1.

151, Figure 4.1 (Spyros Sarigiannidis): Node (Egypt, 28) should be (Egypt, 20).

## Chapter 5

186, line -2 (Franklin Chen): the expression given to ML should be
foldr op@ [] [[1], [2,3], [4,5,6]];

187, line 3 (Franklin Chen): the expression given to ML should be
foldr newmem [] (explode"Margaret");

209, line 8 (Wei Ke): replace "to the left" by "to the right".

## Chapter 6

237, line -12, Exercise 6.20 (Wei Ke): Delete the final right parenthesis.

239, line -6 (Wei Ke): Replace "mathematical induction" by "complete induction".

246, line 1: the Boyer and Moore theorem prover has been superseded by ACL2. A suitable book is Computer-Aided Reasoning: An Approach by Matt Kaufmann, Panagiotis Manolios, and J Strother Moore, Kluwer, 2000.

246: In the last line of the statement of Theorem 19, delete "and a"

249, line -9 (Wei Ke): in tmergesort, replace List.take by take and List.drop by drop. (This example is self-contained and does not refer to external functions.)

## Chapter 7

279, line -9 (Wei Ke): ML should respond to the declaration of zz with val zz = ...

280, line 9 (Wei Ke): replace "semir-ing" with "semi-ring"

290, line -6 (Wei Ke): replace 1356 with 1415 (the min operation returns "Agincourt")

296, line 18 (Wei Ke): in the functor declaration, replace the structure parameter Order by Item.

297, line 13 (Wei Ke): Replace StringPQ by StringPQueue.

## Chapter 8

321, line 3 (Wei Ke): The keyword "raise" should not be slanted.

329, line 10 (Wei Ke): Replace "ImpSeq.take(5, it)" by "ImpSeq.take(it, 5)".

332: in the figure, all nodes should be the same shade of grey

335,-1 (Namhyun Hur): missing space between "Vector" and "declares"

348, line 3 (Wei Ke): Replace "the testing" by "testing".

348, line -5 and 350, line 3 (Gilbert Bthn): Replace "Substring.all" by "Substring.full"

351, Exercise 8.32: all the escape sequences require a terminating semicolon, as in &lt;. Moreover one may use a literal " instead of the &quot; sequence.

## Chapter 9

360, lines 2 and 5 (Gilbert Bthn): Replace "Substring.all" by "Substring.full"

381 (Claus-Peter Wirth): the first grammar rule for Term is missing the "." symbol: it should be

Term = % Id Id* . Term

388, exercise 9.21 (Wei Ke): Replace = by equivalence (equality with three bars).

393, Section 9.13 (Wei Ke): The first function declaration should be

`fun stdRead a = Lambda.inst stdEnv (ParseTerm.read a);`

393, Section 9.13 (Wei Ke): In ML's responses, type term should be Lambda.t.

394, line -2 (Wei Ke): Change "YV (%g n.(" to "YV (%g n. (", or possibly add "." to LamKey.symbols (368, line -6) to eliminate the need for a space between "." and "(".

## Chapter 10

404, exercise 10.7 (Wei Ke): Replace "premise" by "proviso".

414, line 7 (Wei Ke): Replace "identifiers, form and read" by "identifier, read".

431, line -3 (Wei Ke): Replace "printpar" by "printParam".

433, line 1 (Wei Ke): Replace "printgoals" by "printGoals".

436, line 2 (Wei Ke): Delete the declaration `infix 6 \$--`

437, line 8 (Wei Ke): Replace "g(y)" by "g(x)".

## Bibliography

452: Grant (1996) has appeared, pages 143-170.

452: Greiner (1996) has appeared, pages 111-141.

453: the URL in Jones (1995) should be http://www.divms.uiowa.edu/~jones/pdp8/

453: in Knuth (1981), the title Seminumerical Algorithms should be italicised

## Syntax Charts

459 (John Reppy): an include specification may also give an explicit signature. A useful example is "include SIG where type t = int".

459 (Martin von Gagern): the "and" loop in Datatype Bindings is unnecessary, because Datatype Bindings themselves contain such a loop.

461 (Martin von Gagern): the constructors of a Datatype Binding should be Names, not Idents. Thus, a constructor may have the form "op **", where ** is any infix operator. (This is the only difference between datatype declarations and datatype specifications, which appear in signatures. Thus, it is a quirk of ML itself.)

461 (Martin von Gagern): sharing constraints may not be joined with and; instead, use a series of sharing constraints.

## Index

469: "~ function 22, 23" is redundant: delete.

472 (Wei Ke): "library, ix" should be "library, xiii"

473 (Wei Ke): "map function/...x sequences" is garbled. The entry (including the previous line) should read "map function/for sequences, 195, 199"

473 (Wei Ke): "ML, evolution of, ix" should be "ML, evolution of, xiii"

473, left column, line -3 (Wei Ke): "Substring structure, 341" should be merged with the "Substring structure" entry near the top of the right column.

469: "as keyword" needs an entry to page 133 (see above)

## Predeclared Identifiers

478 (Sarah Mount): function ignore has type 'a->unit, and not int->unit as stated.

An erratum shown in this style has been corrected in the 1997 reprinting

Last revised: Monday, 12 March, 2018

Lawrence C. PaulsonComputer LaboratoryUniversity of Cambridge