Scala 2

A beta version of the new Scala compiler (aptly named nsc) is now available. It's written in Scala and implements a new version of the language (aptly named Scala 2), which boasts some pretty tempting features:

  • generalized package visibility rules (a small thing, but sorely missed in Java)
  • a new mixin composition model
  • a generalized implicit parameter mechanism to replace views (views always seemed like a slightly unfinished feature, a problem which seems to have been neatly solved)
  • more flexible typing rules for pattern matching, effectively introducing GADTs

There are some other changes as well, but I expect implicit parameters and GADTs to get the most attention. Scala has been mentioned quite frequently lately, and I imagine quite a few people will want to take a(nother) look. In addition to the general information about this release, there's also a detailed description of the language changes.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

How much shorter did the comp

How much shorter did the compiler get in the rewrite?

Great question...

...but I don't have the source for the old Scala compiler, and I'm not sure it was ever formally available... So I'm afraid I can't answer it.

Compiler size.

Odersky mentioned this in his speech at POPL. I did not write down the exact numbers but the old compiler was nearly 40kloc and the new was in the low 20's iirc.

Check out the Scala pages; th

Check out the Scala pages; their public subversion repository contains both the old and new versions of the compiler.

Odersky Slides

You can see the slides from his talk:

POP Slides PDF

old scalac1 48,484 loc
new scalac2 22,823 loc
javac3 28,173 loc

The slides are quite informative.

I guess it's time to add Scal

I guess it's time to add Scala to the todo list...

Bake for four years ...

For historical perspective, Ehud first mentioned Scala on LtU (AFAIK) in in February of 2002.

I know of Scala for quite som

I know of Scala for quite some time, obviously. But I never got around to delve into it properly. I guess I should.

Shared state concurrency is hard

Is it just me, or is their example of extending a StringIterator(someString) with SyncIterator with RichIterator a nice trap to lure the unsuspecting into unspeakableMayhem if they call foreach from more than one thread?


I'm not sure I really like that example... Seems like they might've found a mixin composition example that didn't also muddy the waters with concurrency. But I guess they were trying to demonstrate the interaction between synchronization and mixin composition, so I suppose they didn't have much of a choice?

I guess this goes back to another conversation about Scala concurrency...

A good discssion of Scala mixins?

I can't put my hands on a good discssion. All I can find is the simple Point2D/3D example. Any suggestions?

Re: Scala mixins?

I'm not sure if this will help, but
Scalable Component Abstractions [pdf] looks to talk about their use.




Since the mixin mechanism has changed somewhat in Scala 2, there's some pretty detailed information in the "detailed description of language changes" linked above. It's definitely a little light on examples, but at least it's up to date...

I am beginning to think that

I am beginning to think that mixins are only good for StringIterators ;-)

See the scala.collections

See the scala.collections API (in the core Scala library) for many good uses of mixins. In particular, mixins are used to enhance mutable collections with observable and synchronized features.