Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
winitzki opened this issue Jan 15, 2019 · 0 comments
Open

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

winitzki opened this issue Jan 15, 2019 · 0 comments

Comments

@winitzki
Copy link

winitzki commented Jan 15, 2019

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.

winitzki added a commit to winitzki/milewski-ctfp-pdf that referenced this issue Oct 21, 2019
winitzki added a commit to winitzki/milewski-ctfp-pdf that referenced this issue Oct 21, 2019
winitzki added a commit to winitzki/milewski-ctfp-pdf that referenced this issue Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant