Skip to content

Commit 4c597bf

Browse files
authored
Merge pull request #2490 from SethTisue/dont-call-it-currying
2 parents 2bd34e5 + 292b84f commit 4c597bf

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

_tour/multiple-parameter-lists.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: tour
3-
title: Multiple Parameter Lists (Currying)
3+
title: Multiple Parameter Lists
44
partof: scala-tour
55

66
num: 12
@@ -96,3 +96,41 @@ println(squares) // List(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)
9696
val cubes = numberFunc((xs, x) => xs :+ x*x*x)
9797
println(cubes) // List(1, 8, 27, 64, 125, 216, 343, 512, 729, 1000)
9898
```
99+
100+
### Comparison with "currying"
101+
102+
You may sometimes see a method with multiple parameter lists referred to as "curried".
103+
104+
As the [Wikipedia article on currying](https://en.wikipedia.org/wiki/Currying) states,
105+
106+
> Currying is the technique of converting a function that takes
107+
> multiple arguments into a sequence of functions that each takes a
108+
> single argument
109+
110+
We discourage the use of the word "curry" in reference to Scala's multiple parameter lists, for two reasons:
111+
112+
1) In Scala, multiple parameters and multiple parameter lists are
113+
specified and implemented directly, as part of the language, rather
114+
being derived from single-parameter functions.
115+
116+
2) There is danger of confusion with the Scala standard library's
117+
[`curried`](https://www.scala-lang.org/api/current/scala/Function2.html#curried:T1=%3E(T2=%3ER))
118+
and [`uncurried`](https://www.scala-lang.org/api/current/scala/Function$.html#uncurried[T1,T2,R](f:T1=%3E(T2=%3ER)):(T1,T2)=%3ER) methods, which don't involve multiple parameter lists at all.
119+
120+
Regardless, there are certainly similarities to be found between
121+
multiple parameter lists and currying. Though they are different at
122+
the definition site, the call site might nonetheless look identical,
123+
as in this example:
124+
125+
```scala mdoc
126+
// version with multiple parameter lists
127+
def addMultiple(n1: Int)(n2: Int) = n1 + n2
128+
// two different ways of arriving at a curried version instead
129+
def add(n1: Int, n2: Int) = n1 + n2
130+
val addCurried1 = (add _).curried
131+
val addCurried2 = (n1: Int) => (n2: Int) => n1 + n2
132+
// regardless, all three call sites are identical
133+
addMultiple(3)(4) // 7
134+
addCurried1(3)(4) // 7
135+
addCurried2(3)(4) // 7
136+
```

0 commit comments

Comments
 (0)