docs.scala-lang icon indicating copy to clipboard operation
docs.scala-lang copied to clipboard

Placeholder FAQ claim overreaches

Open som-snytt opened this issue 3 years ago • 4 comments

Reproduction steps

scala 2.13.8> List(42).flatMap(List(_ + 1))
                                    ^
              error: missing parameter type for expanded function ((<x$1: error>) => x$1.$plus(1))

scala 2.13.8> List(42).flatMap(List apply _ + 1)
val res1: List[Int] = List(43)

Problem

The FAQ claims the function can't be written with placeholder syntax.

som-snytt avatar Mar 06 '22 23:03 som-snytt

~I wouldn't call that "placeholder syntax", just because it's underscore? Looks like explicit eta-expansion syntax to me, and that's something else.~

The actual FAQ wording is:

The latter function cannot be written using the _ syntax

I wouldn't mind changing the wording a bit, but I don't think we should remove the claim altogether given that this List apply _ business is corner-case style weirdness that would never have occurred to me to even try and certainly would never occur to a language newcomer.

SethTisue avatar Apr 20 '22 15:04 SethTisue

It's place holder syntax, where it's translated to x => expr(x).

I remember when I first saw someone point out how infix enables extra underscore powers. It seems magical at first, but is just ordinary syntax. Precedence rules matter in this example.

som-snytt avatar Apr 20 '22 15:04 som-snytt

It's place holder syntax, where it's translated

Oops, I thought I'd removed that sentence, after Dale set me straight. I've strikethroughed it.

SethTisue avatar Apr 20 '22 17:04 SethTisue

Taxi drivers are on strikethru, so let me know if you need a ride from the airport.

som-snytt avatar Apr 20 '22 17:04 som-snytt

FAQ is for brevity. That's why we call it FAQ for short.

som-snytt avatar Mar 09 '23 09:03 som-snytt