hmemcpy / milewski-ctfp-pdf

Bartosz Milewski's 'Category Theory for Programmers' unofficial PDF and LaTeX source
https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/
Other
10.91k stars 581 forks source link

Misleading Scala code in chapter 9, section "Currying" #174

Open winitzki opened 5 years ago

winitzki commented 5 years ago

The functions catstr and catstr' defined in Haskell are equivalent, but the Scala code defines two functions (named the same, catstr?) that are not equivalent, despite what the text says. The proposed changes are about code snippets 3, 4, and 5. The first Scala definition should perhaps become

val catstr(s: String)(s1: String): String = s ++ s1

The second definition could become

val catstr2(s: String): String => String = s1 => s + s1

The third snippet is then

val greet: String => String = catstr("hello")

and then indeed the definition of greet can use either catstr or catstr2 interchangeably, just like in the Haskell code.