Scala 2.9: plans for type inference of function parameters with default arguments?

Scala has had good stuff added for quite a while, but as it gains popularity it will get increasingly more stable. People who were around before 2.8 had much more leverage on modifying the language than people nowdays -- both because they represented a bigger percentage of users, and because the language was more flexible Take, for instance, your issue with erasure. As a 2.0 user you'd have a way bigger chance of getting something done about it than you have now.In fact, the impact that would have in compatibility is pretty much a guarantee that it won't happen anymore, unless Java leads You come from a scripting language.

Scripting languages are very much concerned with I/O, because that's their butter and bread. For Scala, any serious I/O is simply relegated to Java libraries -- that's kind of the point of having Scala be compatible with Java, after all Furthermore, your characterization of 4662 is, actually, completely wrong.It was not broken at all though a change in behavior made arguably incorrect code work again. This is 4662 in a nutshell: val source = scala.io.Source.

FromFile(new java.io. File("test1. File")) use(source) val lines = source.

GetLines Since source is an Iterator it is gone once you use it.It was a coincidence that you could reuse it after calling toString on it, not an intrinsic guarantee Type erasure is not so bad. In fact, it is a sign of bad design if it gets much in the way -- you are not supposed to check what the type of something is, but to call methods on it and let it handle itself. Not to say it isn't annoying at times, but not so badly.

Alas, it is a fundamental choice in having seamlessly compatibility with Java, and it was very consciously made. I don't see Scala leading the way out of it One of the new languages that promise to get rid of erasure, and maintain compatibility with Java, is Ceylon. If Ceylon manages that, and I'm firmly in the doubters camp, then Scala could follow Also, on a recent discussion of closures for Java 8 indicated the possibility that something might be done about erasure.

If that turns out to be true, then Scala could cash in as well As for the question, I agree that these types could be inferred. I'm not sure anyone is doing something with default parameters, however -- priorities for the moment lie elsewhere.

Scala has had good stuff added for quite a while, but as it gains popularity it will get increasingly more stable. People who were around before 2.8 had much more leverage on modifying the language than people nowdays -- both because they represented a bigger percentage of users, and because the language was more flexible. Take, for instance, your issue with erasure.As a 2.0 user you'd have a way bigger chance of getting something done about it than you have now.

In fact, the impact that would have in compatibility is pretty much a guarantee that it won't happen anymore, unless Java leads. You come from a scripting language. Scripting languages are very much concerned with I/O, because that's their butter and bread.

For Scala, any serious I/O is simply relegated to Java libraries -- that's kind of the point of having Scala be compatible with Java, after all. Furthermore, your characterization of 4662 is, actually, completely wrong.It was not broken at all, though a change in behavior made arguably incorrect code work again. This is 4662 in a nutshell: val source = scala.io.Source.

FromFile(new java.io. File("test1. File")) use(source) val lines = source.

GetLines Since source is an Iterator, it is gone once you use it.It was a coincidence that you could reuse it after calling toString on it, not an intrinsic guarantee. Type erasure is not so bad. In fact, it is a sign of bad design if it gets much in the way -- you are not supposed to check what the type of something is, but to call methods on it and let it handle itself.

Not to say it isn't annoying at times, but not so badly. Alas, it is a fundamental choice in having seamlessly compatibility with Java, and it was very consciously made. I don't see Scala leading the way out of it.

One of the new languages that promise to get rid of erasure, and maintain compatibility with Java, is Ceylon. If Ceylon manages that, and I'm firmly in the doubters camp, then Scala could follow. Also, on a recent discussion of closures for Java 8 indicated the possibility that something might be done about erasure.

If that turns out to be true, then Scala could cash in as well. As for the question, I agree that these types could be inferred. I'm not sure anyone is doing something with default parameters, however -- priorities for the moment lie elsewhere.

Sorry about responding late. I'm really surprised you think that the only problem with type erasure is that you can't check the type of something. Type erasure, at least in Java, means that if you have e.g. A ListT, you can't even create a new T object!

And "checking the type" is in fact a normal Scala idiom with match. Look at the Hadoop API -- you need these ugly setFooClass(), setBarClass(), setBazClass() calls everywhere precisely to get around the fact that you can't create a new T given a FooT. – Urban Vagabond Sep 4 at 0:47 @Urban I don't think instantiating a T is a good idea to begin with.

Factories are the proper way to do that, and you can pass factories around. In fact, even Manifest is a factory, of sorts. – Daniel C.

Sobral Sep 4 at 1:29 Why not? Factories are only the "proper" way to do that because type erasure forces you to do this. Also, as I said, using 'match' is one of the accepted Scala idioms.

The Scala2e book gives lots of arguments why it isn't always the best way to be forced to implement everything using methods defined on classes. – Urban Vagabond Sep 4 at 2:27 1 @Urban To put it simply, it violates the I part of SOLID principles. You can look up SOLID principles and you'll find lots of information.

– Daniel C. Sobral Sep 4 at 23:35.

Yes Because the underlying VM abstracts any access to the world "outside", there is basically the option to either ship with compiled code, making Scala not platform-independent or using things like java.io. File which is just utterly broken. Java 7 has (after only 15 years) finally added some usable file system API, which is already targeted as far as I know by the in-progress Scala IO library.

Another point is the support of other runtime platforms. It isn't a good idea to release a Scala IO library which has only a JVM implementation. So basically: Having some decent IO library was made possible by Java 7 a few weeks ago.

Considering that Scala will not drop support for Java 6 (and 5) in the near future, don't expect IO shipping with the standard library soon. You are using it wrong. But feel free to create your own language which does everything better if you think "Scala designers will realize the folly".

Reified generics are hard to combine with higher-kinded types. And if I had to choose, I will take HKT over reified generics every time. Ahhh .. right.

These things aren't your questions. Answer to your actual question: It could be done, but people like to keep the rules simple. So probably not.

1 Saying "You are using it wrong. But feel free to create your own language which does everything better if you think "Scala designers will realize the folly" is not very friendly. It was a valid question and probably in minds of most people coming from Scripting background.

– Salil Aug 24 at 7:03 Salil: I didn't intend to sound harsh. Considering that pretty much every scripting language is untyped I don't understand your last sentence. Care to elaborate?

– soc Aug 24 at 11:01 most of the people who are new to Java world, be it Scripting or C++/C#, do not appreciate 'type erasure'. It results into special cases while type checking and in Scala case statements also. Manifests themselves are a way to circumvent the limitations of type erasure.'Urban Vagabond' raised a valid point about why Scala decided to continue the same 'mistake' Java did.

Your reply along the line of 'go, create your own language' sounded unduly harsh. – Salil Aug 24 at 12:10 I think we pretty much agree. I think everyone has understood the negative aspects of type erasure.

But it is just not a solution to say "just fix it" without mentioning how. That's why I really would like to see a working solution, instead of pointing out the obvious. – soc Aug 24 at 12:19 You really shouldn't respond with snippy comments on StackOverflow, keep them to yourself or assert your dominance over n00bs on scala-user – ThaDon Aug 247 at 15:30.

I don't have enough rep power to add this as a comment, so I must add as an answer. Also this is too long for a comment. Regarding the main question, I agree that the types of input parameters with default values could be inferred.

I did the following query at their Scala issues tracker and didn't find an applicable feature request. So perhaps you could file one there. Project = SI AND (summary ~ "default" AND summary ~ "value") no comment no comment As others have pointed out, reification (i.e.

Not type erasure) makes higher-kinded generics more difficult to implement. Here is a direct quote from section 6.1 of "Generics of a Piessens, Moors, Odersky. Since Scala uses type erasure in the back-end, the extent of the changes is limited to the type checker.

Clearly, our extension thus does not have any impact on the run-time characteristics of a program. Ironically, as type erasure is at the root of other limitations in Scala, it was an important beneיִt in implementing type constructor polymorphism. Similar extensions in languages that target the .

NET platform face a tougher challenge, as the virtual machine has a richer notion of types and thus enforces stricter invariants. Unfortunately, the model of types does not include higher-kinded types. Thus, to ensure full interoperability with genericity in other languages on this platform, compilers for languages with type constructor polymorphism must resort to partial erasure, as well as code specialisation in order to construct the necessary representations of types that result from abstract type constructors being applied to arguments.

You can review that paper for an explanation of why higher-kinded generics are important. Although Scala 2.8 does not apparently use them extensively in their new collections library, so far I find it is impossible to implement my category theory library in a subtyped elegant manner without higher-kinds (contrast this with Scalaz non-subtyped design which I find to be extremely complex). Daniel C.

Sobral regarding your comment below your answer, I think it is the D principle in SOLID that is violated by constructors. Urban Vagabon, factories should be used to achieve inversion-of-control, a/k/a the Hollywood principle. See also Gilad Bracha's blog "Constructors Considered Harmful".

This is not intended to be the most complete or best answer, rather some partial thoughts which might add to this knowledge-base.

Software developer, student, guitarist, Scala enthusiast. Which property of Scala's type-system make it Turing-complete? Is non-local return in Scala new?

How pure and lazy can Scala be? For Scala are there any advantages to type erasure? Scala 2.9: plans for type inference of function parameters with default arguments?

How to hide Akka remote actors from lookup?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions