Scala future, Sing#

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Tue Aug 25 03:37:51 PDT 2009


Walter Bright wrote:

> Jari-Matti Mäkelä wrote:

>> - bloat: Scala is more lightweight. I've heard Walter say that he doesn't
>> like e.g. library defined control structures -
> 
> Actually, you can do them with "lazy" function arguments. There was an
> example somewhere of doing control structures with it.

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)

> 
>> it's double-edged sword, and
>> D and Scala have taken different paths here (in D if something is
>> commonly used and it can be made built-in, it will be added to the
>> compiler, in Scala it's the opposite).
> 
> That's not quite right. I'll add things to the core if there is a good
> reason to - the compiler can do things a library cannot. For example,
> string literals.

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

>> - bugs: IMHO the unspecified parts of D and the huge amount of bugs made
>> it unusable for me. Luckily I found Scala and have been really happy with
>> it. I've only found maybe 1-2 bugs in it during the last 1.5 years. I
>> usually find about 5-10 bugs in DMD in 15 minutes after coming back to D.
> 
> I couldn't find any bugs you've submitted to the D bugzilla. If you
> don't submit them, they won't get fixed <g>.

I've submitted couple of reports years ago and luckily some of them have 
already been fixed. Maybe the search is broken.
 
>> And I'm
>> also so happy to find that thanks to authors' knowledge of type systems
>> (dependent types, HM, System F, etc.) 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[][]"



More information about the Digitalmars-d mailing list