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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Tony Morris

-----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-----

Reply | Threaded
Open this post in threaded view
|

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

Jason Zaugg
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 <[hidden email]> 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-----
>
>
Reply | Threaded
Open this post in threaded view
|

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

Paul Phillips-3
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.

--
Paul Phillips      | One way is to make it so simple that there are
Future Perfect     | obviously no deficiencies. And the other way is to make
Empiricist         | it so complicated that there are no obvious deficiencies.
pull his pi pal!   |     -- Hoare
Reply | Threaded
Open this post in threaded view
|

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

Tony Morris

-----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.

- --
Tony Morris
http://tmorris.net/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0oXnIACgkQmnpgrYe6r61KNQCdEzC0oCx1T+2mwwLD1YCbLMF1
nqIAniCvI9QDeh9ai0IqvLrpSIrCd8St
=sW3e
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|

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

David Hall-17
On Sat, Jan 8, 2011 at 4:54 AM, Tony Morris <[hidden email]> 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...

-- David

>
> - --
> Tony Morris
> http://tmorris.net/
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk0oXnIACgkQmnpgrYe6r61KNQCdEzC0oCx1T+2mwwLD1YCbLMF1
> nqIAniCvI9QDeh9ai0IqvLrpSIrCd8St
> =sW3e
> -----END PGP SIGNATURE-----
>
>
Reply | Threaded
Open this post in threaded view
|

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

Jason Zaugg
On Sat, Jan 8, 2011 at 6:24 PM, David Hall <[hidden email]> 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/compiler/scala/tools/nsc/typechecker/Typers.scala#L789
[2] http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/src/compiler/scala/tools/nsc/typechecker/Typers.scala#L988