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

Type pretty-printer omits parentheses around by-name params, writing => A => B instead of (=> A) => B #6434

Closed
scabug opened this issue Sep 27, 2012 · 5 comments
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Sep 27, 2012

Variation of #5661:

$ ./qbin/scala
Welcome to Scala version 2.10.0-20120925-012651-d6a933c4f5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_35).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def f(x: => Int): Int = x
f: (x: => Int)Int

scala> f _
res0: => Int => Int = <function1>

Note: d6a933c4f5 is a local commit on top of ffaa3cb89edc1407c99c89f36248358c16887fe7 from 2.10.x, but it's just a small change:

--- a/src/library/scala/package.scala
+++ b/src/library/scala/package.scala
@@ -95,7 +95,10 @@ package object scala {
   val Equiv = scala.math.Equiv
 
   type Fractional[T] = scala.math.Fractional[T]
+  val Fractional = scala.math.Fractional
+
   type Integral[T] = scala.math.Integral[T]
+  val Integral = scala.math.Integral
 
   type Numeric[T] = scala.math.Numeric[T]
   val Numeric = scala.math.Numeric
@scabug
Copy link
Author

@scabug scabug commented Sep 27, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6434?orig=1
Reporter: @Blaisorblade
Assignee: @JamesIry
Affected Versions: 2.9.2, 2.10.0

@scabug
Copy link
Author

@scabug scabug commented Sep 30, 2012

@jsuereth said:
while the () is useful, I don't think this is actually a bug, more an improvement. IIRC, => A => B => C is a valid function type.

@scabug
Copy link
Author

@scabug scabug commented Sep 30, 2012

@Blaisorblade said (edited on Sep 30, 2012 6:03:34 PM UTC):
=> A => B is a valid type, just the wrong one. Right-associativity makes that equal to => (A => B) (I'd file a separate bug otherwise), while we want a different type, (=> A) => B; hence omitting parentheses changes the type. The REPL output below suggests that => A => B is indeed right-associative as expected:

scala> val v: ((=> Int) => Int) = f _
v: => Int => Int = <function1>

scala> val v: (=> (Int => Int)) = f _
<console>:1: error: no by-name parameter type allowed here
       val v: (=> (Int => Int)) = f _
               ^

scala> val v: (=> Int => Int) = f _
<console>:1: error: no by-name parameter type allowed here
       val v: (=> Int => Int) = f _
               ^

@scabug
Copy link
Author

@scabug scabug commented Jan 23, 2013

@adriaanm said:
James, care to put some more parens in our types? (Because we like parens.)

@scabug
Copy link
Author

@scabug scabug commented Jan 23, 2013

@scabug scabug closed this Jan 25, 2013
@scabug scabug added this to the 2.10.1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant