Is there an example where the insertion of () into an argument list did actually something useful?

573 views
Skip to first unread message

Simon Ochsenreither

unread,
Jun 7, 2013, 5:02:54 PM6/7/13
to scala-i...@googlegroups.com
scala> List(1,2,3).toSet()
res0: Boolean = false

lint says:

<console>:8: warning: Adapting argument list by inserting (): this is unlikely to be what you want.
signature: GenSetLike.apply(elem: A): Boolean
given arguments: <none>
after adaptation: GenSetLike((): Unit)
List(1,2,3).toSet()
^

Simon Ochsenreither

unread,
Jun 7, 2013, 6:14:03 PM6/7/13
to scala-i...@googlegroups.com
Might be obvious, but

scala> Set(1,2,3)()

doesn't work “of course”:

<console>:8: error: not enough arguments for method apply: (elem: Int)Boolean in trait GenSetLike.
Unspecified value parameter elem.
              Set(1,2,3)()
                        ^


Paul Phillips

unread,
Jun 7, 2013, 6:18:18 PM6/7/13
to scala-i...@googlegroups.com
Re: the subject line, I thought I'd be able to think of one - at least one where it's harmless - but they're not exactly springing to mind.

On Fri, Jun 7, 2013 at 3:14 PM, Simon Ochsenreither <simon.och...@gmail.com> wrote:
scala> Set(1,2,3)()

doesn't work “of course”

Type-safe contains FTW.

Here's an interesting look at the adhocity of the implementation. Why do these issue different errors?

scala> Set(1, 2, 3) contains ()
<console>:8: error: not enough arguments for method contains: (elem: Int)Boolean.
Unspecified value parameter elem.
              Set(1, 2, 3) contains ()
                           ^

scala> Set(1, 2, 3) contains (())
<console>:8: error: type mismatch;
 found   : Unit
 required: Int
              Set(1, 2, 3) contains (())
                                     ^

 


Simon Ochsenreither

unread,
Jun 7, 2013, 6:29:41 PM6/7/13
to scala-i...@googlegroups.com

scala> Set(1,2,3)()

doesn't work “of course”

Type-safe contains FTW.

def has(elem: T): Boolean maybe?


Here's an interesting look at the adhocity of the implementation. Why do these issue different errors?

I have no idea, but actually I'm even more confused by the question why scalac doesn't try to “adapt the argument list by inserting ()” in these two cases.

Paul Phillips

unread,
Jun 7, 2013, 7:09:23 PM6/7/13
to scala-i...@googlegroups.com

On Fri, Jun 7, 2013 at 3:29 PM, Simon Ochsenreither <simon.och...@gmail.com> wrote:
I have no idea, but actually I'm even more confused by the question why scalac doesn't try to “adapt the argument list by inserting ()” in these two cases.

It does, but Set by virtue of its invariance has "type-safe contains", so they cannot be so adapted - thus "type-safe contains ftw."

scala> Set(1, 2, 3) contains "a"
<console>:8: error: type mismatch;
 found   : String("a")
 required: Int
              Set(1, 2, 3) contains "a"
                                    ^

scala> List(1, 2, 3) contains "a"
res2: Boolean = false

Simon Ochsenreither

unread,
Aug 6, 2013, 3:06:33 PM8/6/13
to scala-i...@googlegroups.com
Another occurrence of this: https://groups.google.com/d/topic/scala-user/4yggJc38tIg/discussion

It has been 2 months since the first mail and no one was able to come up with a reasonable example where this behavior might do any “good”.

Therefore, in the absence of any convincing example, I'd like to propose the deprecation of this “feature”.

Adriaan Moors

unread,
Aug 6, 2013, 5:36:14 PM8/6/13
to scala-i...@googlegroups.com
With dbuild we'll very soon be able to answer these questions empirically.
Disable feature. Recompile the world. Sit back. Be convinced, or convincing.




--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Simon Ochsenreither

unread,
Sep 15, 2013, 1:01:30 PM9/15/13
to scala-i...@googlegroups.com
Another example by Paul:

scala> class A[T](val x: T)
defined class A

scala> new A
res0: A[Unit] = A@5534578f

Paul Phillips

unread,
Sep 15, 2013, 2:22:58 PM9/15/13
to scala-i...@googlegroups.com
To be clear, I didn't intend this as an example of doing something useful. Only as an example of doing something. 

Simon Ochsenreither

unread,
Sep 15, 2013, 3:04:04 PM9/15/13
to scala-i...@googlegroups.com

To be clear, I didn't intend this as an example of doing something useful. Only as an example of doing something. 

Zes, was intended to be an example why it is bad, not why it is useful.

Som Snytt

unread,
Sep 15, 2013, 3:56:48 PM9/15/13
to scala-internals
Next time my mother begs me to set "an example by doing something, anything, it doesn't have to be useful," I will refer her to this thread.

I will now change out of the t-shirt I slept in and into my "result of the insertion of () that did something" T-shirt.  On the other side, it says, "Unit".

No wait, let me get out my purple tie-dye t-shirt that says the same thing on the front, and on the back it reads:

"Moon Unit Zappa."

Reply all
Reply to author
Forward
0 new messages