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

spec: incorrect eta-expansion example in section 6.7.1 (Method Values) #6054

Closed
scabug opened this issue Jul 10, 2012 · 11 comments
Closed

spec: incorrect eta-expansion example in section 6.7.1 (Method Values) #6054

scabug opened this issue Jul 10, 2012 · 11 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jul 10, 2012

Section 6.7.1 ("Method Values") in the language spec says:

bq. Example 6.7.1 The method values in the left column are each equivalent to the anonymous functions (§6.23) on their right.

List.map2(xs, ys)_     x => List.map2(xs, ys)(x) 

But I don't think this expansion is correct. 6.7 says "e _ represents e
converted to a function type by eta expansion (§6.26.5)", and in 6.26.5,
we see that eta expansion introduces fresh names for subexpressions. So
the actual expansion is:

{ val x0 = xs; val x1 = ys; x => List.map2(x0, x1)(x) } 

for some fresh names x0 and x1.

The difference matters if a subexpressions has side effects. So for
example with eta expansion we see the side effects immediately:

scala> def f(a: Int)(b: Int) { } 
f: (a: Int)(b: Int)Unit 

scala> def g = { println("hey!"); 4 } 
g: Int 

scala> f(g) _ 
hey! 
res11: Int => Unit = <function1> 

Whereas without the introduction of fresh names, evaluation is deferred:

scala> f(g)(_) 
res12: Int => Unit = <function1> 

because the behavior in this latter case is governed by 6.23
("Placeholder Syntax for Anonymous Functions"), not 6.26.5.

@scabug
Copy link
Author

scabug commented Jul 10, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6054?orig=1
Reporter: @SethTisue

@scabug
Copy link
Author

scabug commented Jul 10, 2012

@SethTisue said:
Johannes Rudolph agrees the example is incorrect (at https://groups.google.com/forum/#!topic/scala-language/W1ZUNDAq7Fc/discussion)

@scabug
Copy link
Author

scabug commented Oct 15, 2013

@gkossakowski said:
Unassigning and rescheduling to M7 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Mar 13, 2014

@adriaanm said:
Wow, good catch! Hope it's fixed correctly by https://github.com/adriaanm/scala-ref-markdown/commit/51f3ac1f36737606a2921a2abca39c1ca7962324

@scabug scabug closed this as completed Mar 13, 2014
@scabug
Copy link
Author

scabug commented Mar 13, 2014

@SethTisue said:
LGTM. (And, great to see the spec wheels turning again.)

@scabug
Copy link
Author

scabug commented Mar 13, 2014

@som-snytt said:
+1, turning as opposed to spinning. But maybe spec examples should use existing API?

@scabug
Copy link
Author

scabug commented Mar 13, 2014

@adriaanm said:
True -- I noticed but had gotten a bit bleary eyed by my twentieth spec bug. Eventually we'll make it literate so that freshness doesn't require human eyes. In the mean time, PR welcome, unless I beat you to it :)

@scabug
Copy link
Author

scabug commented Mar 13, 2014

@scabug
Copy link
Author

scabug commented Mar 13, 2014

@som-snytt said (edited on Mar 13, 2014 8:02:15 PM UTC):
I love the minty fresh palette.

You bleat me to it [sic] but here's a version with some virtues. I'm especially happy with the Option example. (But the point, that your by-name param isn't evaluated during eta-expansion, isn't in the spec yet, I think.) Also happy with showing eval of other parts of the expr, since people are supposedly confused by what underscore encompasses.

https://github.com/adriaanm/scala-ref-markdown/pull/show/2/files/abbbb4e#diff-abbbb4e81bd75c5ebc51a0101b59b381

You know the guy who annoys you by coming up to your car at a stop light with a dirty squeegee? I hope I'm not that guy.

@scabug
Copy link
Author

scabug commented Mar 13, 2014

@adriaanm said:
It's only annoying because the squeegee is dirty.

@scabug
Copy link
Author

scabug commented Mar 13, 2014

@som-snytt said:
Code review is the dirty rag he pulls from his back pocket after he's done with the squeegee. FTR, my rag is a clean old sock. I know it's clean because it was clean last time I wore it.

@scabug scabug added this to the 2.11.0-RC3 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants