4 Apr 2007 09:54
Re: + and List
martin odersky <odersky <at> gmail.com>
2007-04-04 07:54:57 GMT
2007-04-04 07:54:57 GMT
On 4/4/07, Bill Venners <bv-jackrabbit <at> artima.com> wrote: > Hi Martin, > > It is interesting that different people are coming up with different > theories about what's going on behind the scenes. I'm not familiar > enough with implicits to know if that's the mechanism here, but you > seem to hint below that it is. If so, then it isn't magic, because I > can use implicits myself. So just to make sure I understand this, let > me ask directly: Is + on Java Strings made possible by Scala's > implicit mechanism? No, + is currently implemented as magic. The compiler frontend simple adds a + method to its internal view of the String class. The backend then emits special code for this. + could be implemented as an implicit, if we are willing to sacrifice some performance, or once we have better optimizations (hopefully real soon now). Have a look at the source in Predef. There you find: implicit def stringWrapper(x: String) = new runtime.RichString(x) implicit def any2stringadd(x: Any) = new runtime.StringAdd(x) The RichString class has a number of utility methods, but no + method. Once implicits are reliably inlined, we could add the + to RichString and do away with the magic. > > I mentioned this once before, but I think the ScalaDoc would be > improved if the lower left hand corner frame was just an alphabetical > listing of types, with traits, objects, and classes all mixed. > However, it is nice to be able to differentiate them. In JavaDoc > interfaces are in italics everywhere, so you can easily differentiate > interfaces from classes. I think definitely traits could be in > italics. To differentiate objects and classes, I'm not sure what to > do. Making one bold seems too strong, because it implies one is more > important that the other. One thing that shows up a lot in the left > hand list, especially if you combine everything into one alphabetical > list, is multiple types with the exact same simple name. So I think > it would really help usability if there was a way in ScalaDoc to add > a little annotation that shows up in parens next to an object to > differentiate different types with the same simple name. If you did > that, then you could potentially differentiate objects and classes > with such annotations, as in: > > List (class) > List (object) > > ... > > Set (abstract) > Set (mutable) > Set (immutable) > > etc. > Good suggestions! Sean is currently overhauling ScalaDoc. I think some of your suggestions were already addressed by him. Cheers -- Martin
RSS Feed