--
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.
this special case where the curly braces are hard-coded into to the partial function syntax
--
Do you only get an Expr on the RHS of the arrow? That would make sense as a compromise, the way you get shortcuts for x => ??? with mild restrictions.
I managed my deep annoyance of partial functions by just not touching them, but I had to use them when I did the last Coursera course. What a pain!
It gets additionally painful if one doesn't want to declare the partial functions inline, but wants to extract them to values for readability: Scala punishes this with requiring even more noise than before!
It's mind-boggling to me that we let people use this stuff.
So I sat down, hacked the compiler.
Instead of
val root: PartialFunction[Double,Double] = {
case d if (d >= 0) => math.sqrt(d)
}
one can write
val root: PartialFunction[Double,Double] =
case d if (d >= 0) => math.sqrt(d)
now, just like with functions.
I'm planning to do the same for
future.onSuccess({case _ => println("Success!")})
so that one can write
future.onSuccess(case _ => println("Success!"))
It shouldn't. Multiple statements always need curly braces. I don't see a difference between regular statements and case statements in that.
On Sat, Feb 01, 2014 at 03:07:23PM -0800, Simon Ochsenreither wrote:
> So I sat down, hacked the compiler.
>
> Instead of
>
> val root: PartialFunction[Double,Double] = {
> case d if (d >= 0) => math.sqrt(d)
> }
>
> one can write
>
> val root: PartialFunction[Double,Double] =
> case d if (d >= 0) => math.sqrt(d)
>
> now, just like with functions.
Seems like a lot of trouble to just save a couple of braces...
Also, does your change support multiple case clauses in a single partial function?
regards,
Tony
It would be nice. In fact I think at one point it was the plan to introduce the partial function alias arrow. I think it was aborted because function arrows need to associate to the right.
Thanks for you comments.
Regarding the =?>: That's currently not part of the plan, I just defined it because signatures tend to become verbose and unreadable PartialFunction and I don't wanted to distract people from the rest.
--
In fact, a match expression requires the braces around the case clauses, so this argues that partial function syntax should also require them for consistency as is currently the case. If I had a vote, this would be my preference.
Most of the partial functions I write have more than one case clause…
> Members, argument lists haven't. I think that’s a reasonable distinction: Don't create possibilities of syntactic variation where it is not necessary, but allow it where it is useful.
I’m still missing what you mean by these ones. E.g., aren’t argument lists surrounded by parentheses, not braces? Can you give examples?
+1
In any case, syntax change suggestions should ideally emerge from
looking closely at the language specification. The spec is still very
accessible and clean. If one can define an unambiguous way to define
case clauses without the braces _and_ manage to keep the spec at the
same size or even shrink it, good. If it just means that we add context
specific syntactic rules, I would think that is a net loss.
FWIF, =?> is pretty ugly and will feed the prejudices of each and
everyone who dislikes Scala because of its cryptic syntax. If at all,
why not re-use the arrow-assoc style arrow:
type -> [-A, +B] = PartialFunction[A, B]
val x: Any -> String = {
case "foo" => "bar"
}
The spec is still very accessible and clean.
If one can define an unambiguous way to define
case clauses without the braces _and_ manage to keep the spec at the
same size or even shrink it, good. If it just means that we add context
specific syntactic rules, I would think that is a net loss.
FWIF, =?> is pretty ugly and will feed the prejudices of each and
everyone who dislikes Scala because of its cryptic syntax.
--
I guess it wasn't clear that that's what I was trying to say. :)
Not at all, things like that happen all the time. No worries!