This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Compiler option to turn off implicit forall A. A => Unit

5 replies
Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I recommend a means by which to turn off a particularly unsafe
function from Predef with the type forall A. A => Unit.

I cannot find any meaningful benefits of such a function, but perhaps
there is an oversight. I wish to emphasise the adjective, "meaningful"
in the previous statement.

Nevertheless, in my opinion, the language subset without this function
is a significant improvement. If I remember rightly, this was once the
case (2.7).

How do I turn it off easily?

Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Compiler option to turn off implicit forall A. A => Unit

If it were a function in Predef, you could shadow it with an import at
the top of each file:

import Predef.{any2unit => _}

But such a function doesn't exist. Instead, the language spec
describes 'Value Discarding', and can't currently be disabled.

-jason

On Sat, Jan 8, 2011 at 2:06 AM, Tony Morris wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I recommend a means by which to turn off a particularly unsafe
> function from Predef with the type forall A. A => Unit.
>
> I cannot find any meaningful benefits of such a function, but perhaps
> there is an oversight. I wish to emphasise the adjective, "meaningful"
> in the previous statement.
>
> Nevertheless, in my opinion, the language subset without this function
> is a significant improvement. If I remember rightly, this was once the
> case (2.7).
>
> How do I turn it off easily?
>
> - --
> Tony Morris
> http://tmorris.net/
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk0nuLEACgkQmnpgrYe6r60Q9QCeOjrJu5X1aGYzk0PP4ecu3Gr+
> EPcAoJhP/6naE8iqWryqYatcnjhqphkN
> =uadj
> -----END PGP SIGNATURE-----
>
>

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Compiler option to turn off implicit forall A. A => Unit

On Sat, Jan 08, 2011 at 09:17:16AM +0100, Jason Zaugg wrote:
> If it were a function in Predef, you could shadow it with an import at
> the top of each file:
>
> import Predef.{any2unit => _}
>
> But such a function doesn't exist. Instead, the language spec
> describes 'Value Discarding', and can't currently be disabled.

And in case there is any major head scratching going on re "If I
remember rightly, this was once the case (2.7)" you're remembering that
it used to be an error to end a block with a declaration.

// used to be an error
{ val x= 5 }

So there is even more value discarding going on these days, but not that
much more.

Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Compiler option to turn off implicit forall A. A => Unit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/01/11 18:39, Paul Phillips wrote:
> On Sat, Jan 08, 2011 at 09:17:16AM +0100, Jason Zaugg wrote:
>> If it were a function in Predef, you could shadow it with an
>> import at the top of each file:
>>
>> import Predef.{any2unit => _}
>>
>> But such a function doesn't exist. Instead, the language spec
>> describes 'Value Discarding', and can't currently be disabled.
>
> And in case there is any major head scratching going on re "If I
> remember rightly, this was once the case (2.7)" you're remembering
> that it used to be an error to end a block with a declaration.
>
> // used to be an error { val x= 5 }
>
> So there is even more value discarding going on these days, but not
> that much more.
>
Thanks guys, despite the bad news.

David Hall 4
Joined: 2009-08-21,
User offline. Last seen 42 years 45 weeks ago.
Re: Compiler option to turn off implicit forall A. A => Unit

On Sat, Jan 8, 2011 at 4:54 AM, Tony Morris wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 08/01/11 18:39, Paul Phillips wrote:
>> On Sat, Jan 08, 2011 at 09:17:16AM +0100, Jason Zaugg wrote:
>>> If it were a function in Predef, you could shadow it with an
>>> import at the top of each file:
>>>
>>> import Predef.{any2unit => _}
>>>
>>> But such a function doesn't exist. Instead, the language spec
>>> describes 'Value Discarding', and can't currently be disabled.
>>
>> And in case there is any major head scratching going on re "If I
>> remember rightly, this was once the case (2.7)" you're remembering
>> that it used to be an error to end a block with a declaration.
>>
>> // used to be an error { val x= 5 }
>>
>> So there is even more value discarding going on these days, but not
>> that much more.
>>
> Thanks guys, despite the bad news.

I wonder if you could write a compiler plugin that did it for you? I
don't know anything about the typer, but it seems like you must be
able to figure out where value discarding happens...

Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Compiler option to turn off implicit forall A. A => Unit

On Sat, Jan 8, 2011 at 6:24 PM, David Hall wrote:
>> Thanks guys, despite the bad news.
>
> I wonder if you could write a compiler plugin that did it for you? I
> don't know anything about the typer, but it seems like you must be
> able to figure out where value discarding happens...

It happens in Typer#adapt [1] [2], but there isn't a hook for a
compiler plugin to get involved.

-jason

[1] http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/src/c...
[2] http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/src/c...

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland