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

Too many uses for "=>" in Scala

3 replies
mbeckerle
Joined: 2008-12-22,
User offline. Last seen 13 weeks 1 day ago.

There's been alot of discussion of late of all the various uses of "_" in
Scala. I certainly could live without most of them, as they seem largely for
expository purposes about very small programs/slideware.

What about the "=>" operator.

It is used for defining functions, by-name parameters, case clauses, and, my
least favorite, self aliases. Probably there are more places that I haven't
listed.

To me it's totally clear that aliases should use the keyword "alias".
By-name parameters should use the keyword "by name". The others are fine as
they occur far more often.

I simply fail to see the rationale for not having a keyword for
self-aliases. I just don't see any analogy at all to functions for this
usage, and I really don't see this construct arising so often that it needs
an operator for code clarity/brevity reasons.

I advocate controlled and slow change for Scala at this point. I.e., for
Scala to evolve in a way which strongly respects compatibility, so while I
want these changes, I would add a keyword, deprecate the prior usage, but
leave it supported for a LONG time, like until the 3rd edition of the Scala
book comes out.

David Pollak
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Too many uses for "=>" in Scala


On Mon, Dec 22, 2008 at 6:29 AM, mbeckerle <mbeckerle [at] dataiti [dot] com> wrote:

There's been alot of discussion of late of all the various uses of "_" in
Scala. I certainly could live without most of them, as they seem largely for
expository purposes about very small programs/slideware.

What about the  "=>" operator.

It is used for defining functions,

Which are functions. 
by-name parameters,

Which are functions. 
case clauses

Which are functions (of the partial variety)  
, and, my
least favorite, self aliases.

Which used to be specified with the "requires" keyword.  The first time I saw the existing self-type syntax, it made perfect sense to me.  While it's not a function definition (as the others above are), I pronounce "=>" as "leads to" which makes sense in all these contexts.  
Probably there are more places that I haven't
listed.

To me it's totally clear that aliases should use the keyword "alias".
By-name parameters should use the keyword "by name". The others are fine as
they occur far more often.

I simply fail to see the rationale for not having a keyword for
self-aliases. I just don't see any analogy at all to functions for this
usage, and I really don't see this construct arising so often that it needs
an operator for code clarity/brevity reasons.

I advocate controlled and slow change for Scala at this point. I.e., for
Scala to evolve in a way which strongly respects compatibility, so while I
want these changes, I would add a keyword, deprecate the prior usage, but
leave it supported for a LONG time, like until the 3rd edition of the Scala
book comes out.


--
View this message in context: http://www.nabble.com/Too-many-uses-for-%22%3D%3E%22-in-Scala-tp21128745p21128745.html
Sent from the Scala mailing list archive at Nabble.com.




--
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: Too many uses for "=>" in Scala
That's clearly rubbish.  Import aliases should obviously use 'as', not 'alias'.

import Foo as Bar

I will not budge an inch on this.  Anyone who says anything contrary to it is completely wrong.

More seriously, I don't have a problem with the multiple uses of =>, as they are very rarely near each other in code.  I suppose the closest you could get is something like:

val lambda: () => Int = 5 match { case 5 => () => 10 }

And even this extreme example is actually not that difficult for my tired eyes to parse.

If there were places where you might see => => in code then I might agree with you.

Generally, words interfere with your reading far more than symbols do, which means that operators that are not relevant in reading code should be written as symbols.  As a particularly motivating example, take a look at Scala's parser combinators, and how readable code using them can be, then consider how it would be with solely alphanumeric operators.

An opposite example is that of Linq, in which countless users mistake Linq for SQL, and don't realise that it's actually at least as powerful as Scala's for-comprehensions (or some equivalent that they actually know, like Python's list comprehensions).

2008/12/22 mbeckerle <mbeckerle [at] dataiti [dot] com>

There's been alot of discussion of late of all the various uses of "_" in
Scala. I certainly could live without most of them, as they seem largely for
expository purposes about very small programs/slideware.

What about the  "=>" operator.

It is used for defining functions, by-name parameters, case clauses, and, my
least favorite, self aliases. Probably there are more places that I haven't
listed.

To me it's totally clear that aliases should use the keyword "alias".
By-name parameters should use the keyword "by name". The others are fine as
they occur far more often.

I simply fail to see the rationale for not having a keyword for
self-aliases. I just don't see any analogy at all to functions for this
usage, and I really don't see this construct arising so often that it needs
an operator for code clarity/brevity reasons.

I advocate controlled and slow change for Scala at this point. I.e., for
Scala to evolve in a way which strongly respects compatibility, so while I
want these changes, I would add a keyword, deprecate the prior usage, but
leave it supported for a LONG time, like until the 3rd edition of the Scala
book comes out.


--
View this message in context: http://www.nabble.com/Too-many-uses-for-%22%3D%3E%22-in-Scala-tp21128745p21128745.html
Sent from the Scala mailing list archive at Nabble.com.


odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Too many uses for "=>" in Scala

I agree that => is not as evident for self aliases as for the other
uses. But anybody who knows a little bit about semantics of OOP knows
that classes are functions that take self as their parameter. So it
makes perfect sense in this respect.

Generally, I try to make Scala bring out deep meaning in its syntax,
rather than going with the obvious. One advantage of that is that deep
meaning is more regular than surface interpretations, so you need
fewer keywords :-)

Cheers

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