Scala future, Sing#

Walter Bright newshound1 at digitalmars.com
Tue Aug 25 11:34:26 PDT 2009


Jari-Matti Mäkelä wrote:
> Agreed, you /can/ do something similar. But in Scala it's the standard way 
> of doing things. If you compare the grammars of both languages, you'll see 
> that Scala is a bit lighter than D (see http://www.scala-
> lang.org/sites/default/files/linuxsoft_archives/docu/files/ScalaReference.pdf)

Yes, it's a bit different philosophy. I like the advantage of built in 
control structures, because that leads to commonality between code 
bases. I wished to avoid things like C++ string, where everyone invents 
their own string class that's incompatible with everyone elses'. Whether 
that latter effect occurs in Scala or not, I don't know.


> I exaggerated a bit. But there are some constructs that some think should 
> not be there, e.g. foreach_reverse.

Perhaps, but you can just ignore it.


> I've submitted couple of reports years ago and luckily some of them have 
> already been fixed. Maybe the search is broken.

Can you provide bug numbers?


>>> Scala is a genius at inferring
>>> types. D doesn't really have a clue.
>> Can you give an example?
> 
> http://d.puremagic.com/issues/show_bug.cgi?id=3042
> 
> auto foo = [ 1, 2L ]; // typeof == int[2u]
> auto foo = [ 2L, 1 ]; // typeof == long[2u]
> auto foo = [ "a", "abcdefgh" ]; // typeof == char[1u][2u] in D1
> auto foo = [ [], [1,2,3] ]; // doesn't even compile
> 
>>> Especially the array literal type inference is really naive.
>> How should it be done?
> 
> You shouldn't use the type of the first given element when constructing the 
> type of the array. If you have [ e_1, ..., e_n ], the type of the literal is
> unify(type_of_e_1, ..., type_of_e_n) + "[]". For instance:
> 
> => typeof([ [], [1,2,3] ])
> => unify( typeof([]), typeof([1,2,3]) ) + "[]"
> => unify( "a[]", unify(typeof(1),typeof(2),typeof(3)) + "[]" ) + "[]"
> => unify( "a[]", unify("int","int","int") + "[]" ) + "[]"
> => unify( "a[]", "int" + "[]" ) + "[]"
> => unify( "a[]", "int[]" ) + "[]"   // a is a local type var, subst = { a -> 
> int }
> => "int[]" + "[]"
> => "int[][]"

Ok.



More information about the Digitalmars-d mailing list