Programming in Scala”
fpiscompanion
fpiscompanion
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Errata 4<br />
run(listOfN(3, "ab" | "cad"))("ababcad") == Right(List("ab","ab","cad"))<br />
run(listOfN(3, "ab" | "cad"))("cadabab") == Right(List("cad","ab","ab"))<br />
run(listOfN(3, "ab" | "cad"))("ababab") == Right(List("ab","ab","ab"))<br />
Pg 184: Exercise 10.13 <strong>in</strong>correctly def<strong>in</strong>es Leaf as a case object. It should be case class:<br />
case class Leaf[A](value: A) extends Tree[A]<br />
Pg 187: Def<strong>in</strong>ition of signature for map on Option has <strong>in</strong>correct return type, should be:<br />
def map[A,B](oa: Option[A])(f: A => B): Option[B]<br />
Pg 238: Def<strong>in</strong>ition of pr<strong>in</strong>tL<strong>in</strong>e has a typo, an extra Return constructor, should be:<br />
def pr<strong>in</strong>tL<strong>in</strong>e(s: Str<strong>in</strong>g): IO[Unit] = Suspend(() => pr<strong>in</strong>tln(s))<br />
Pg 240: REPL session has a typo, should be:<br />
val g = List.fill(100000)(f).foldLeft(f) {<br />
}<br />
(a, b) => x => Suspend(() => ()).flatMap { _ => a(x).flatMap(b)}<br />
Note: we could write a little helper function to make this nicer:<br />
def suspend[A](a: => IO[A]) = Suspend(() => ()).flatMap { _ => a }<br />
val g = List.fill(100000)(f).foldLeft(f) {<br />
}<br />
(a, b) => x => suspend { a(x).flatMap(b) }<br />
Pg 241: TrailRec should be TailRec at the top of the page.<br />
Pg 285: Code snippet has an <strong>in</strong>correctly named type parameter, currently reads:<br />
case class Await[A,O](<br />
req: Is[I]#f[A], recv: Either[Throwable,A] => Process[Is[I]#f,O]<br />
) extends Process[Is[I]#f,R] // `R` should be `O`<br />
Should read: