osdir.com
mailing list archive

Subject: Re: Proposed syntax change in Scala - msg#00073

List: lang.scala

Date: Prev Next Index Thread: Prev Next Index
Would do people think of the idea? Should we make `=' optional in function definitions, for smoothing the path for people coming from Java?
I like Scala's syntax just the way it is. I'm afraid too much optional syntax will negate the benefits of the current uniformity. Therefore, I'd vote for a Java-migration error message.

Or is a better error message enough? Are there are other traps you fell into that you think are worth addressing?
The only thing that I can remember that surprised me was the lack of a postfix '++' operator, as in 'i++', but I don't miss it.

adriaan

ps: Yes, I'm working on higher-order subtyping ;-) I'm currently experimenting with extending Featherweight Scala based on Higher- Order Subtyping by Pierce and Steffen.



Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: Proposed syntax change in Scala

I vote for a better error message. --Stephane martin odersky wrote: Scala is generally easy to learn when coming from Java, but here's a trap: If you write: def square(x: int): int { return x * x } You get: error: illegal start of declaration def square(x: int): int { return x * x } with the error point at the `return'. This is very cryptic, even if it makes perfect sense if you know what's going on. (What goes on, in fact, is that the block in { ... } is parsed as a refinement of the type `int'. Only declarations are allowed in refinements, and the `return' is a statement, not a declaration). One remedy would be to have a specialized error message in the compiler, something like: error: illegal start of declaration in refinement, or missing `=' in front of the `{' Another remedy would be to allow the code above, by making `=' optional for `def'-definitions. In that case, the return type of a function could no longer have a refinement, unless the type appears in parentheses. I.e. def foo: C { type T = int } = ... would be illegal, you'd have to write: def foo: (C { type T = int }) = ... [[[[ In case this is deemed too drastic, we could also allow an optional `with' between a class and its refinement, i.e. C with { type T = int} and C { type T = int } would be equivalent. The `with' form would still be usable as a function return type. I.e. def foo: C with { type T = int } = ... would be OK. Note: I am currently not convinced that the `with' variant is worth it, I just wanted to throw it in because it is relevant to the discusssion. ]]]] Would do people think of the idea? Should we make `=' optional in function definitions, for smoothing the path for people coming from Java? Or is a better error message enough? Are there are other traps you fell into that you think are worth addressing? Cheers -- Martin

Next Message by Date: click to view message preview

Why name: type?

What is the reasoning behind setting declaration style to the "name : Type" as opposed to "Type name"?

Previous Message by Thread: click to view message preview

Re: Proposed syntax change in Scala

I vote for a better error message. --Stephane martin odersky wrote: Scala is generally easy to learn when coming from Java, but here's a trap: If you write: def square(x: int): int { return x * x } You get: error: illegal start of declaration def square(x: int): int { return x * x } with the error point at the `return'. This is very cryptic, even if it makes perfect sense if you know what's going on. (What goes on, in fact, is that the block in { ... } is parsed as a refinement of the type `int'. Only declarations are allowed in refinements, and the `return' is a statement, not a declaration). One remedy would be to have a specialized error message in the compiler, something like: error: illegal start of declaration in refinement, or missing `=' in front of the `{' Another remedy would be to allow the code above, by making `=' optional for `def'-definitions. In that case, the return type of a function could no longer have a refinement, unless the type appears in parentheses. I.e. def foo: C { type T = int } = ... would be illegal, you'd have to write: def foo: (C { type T = int }) = ... [[[[ In case this is deemed too drastic, we could also allow an optional `with' between a class and its refinement, i.e. C with { type T = int} and C { type T = int } would be equivalent. The `with' form would still be usable as a function return type. I.e. def foo: C with { type T = int } = ... would be OK. Note: I am currently not convinced that the `with' variant is worth it, I just wanted to throw it in because it is relevant to the discusssion. ]]]] Would do people think of the idea? Should we make `=' optional in function definitions, for smoothing the path for people coming from Java? Or is a better error message enough? Are there are other traps you fell into that you think are worth addressing? Cheers -- Martin

Next Message by Thread: click to view message preview

Re: Proposed syntax change in Scala

On Mon, Aug 28, 2006 at 10:06:18AM +0200, martin odersky wrote: > One remedy would be to have a specialized error message in the compiler, > something like: > > error: illegal start of declaration in refinement, or missing `=' in front > of the `{' > > Another remedy would be to allow the code above, by making `=' optional for > `def'-definitions. > In that case, the return type of a function could no longer have a > refinement, unless the type appears in parentheses. I'd improve the error message rather than fudging the syntax. That way lies Perl... -- Jamie Webb
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by