www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - incompatible types!

reply Caligo <iteronvexor gmail.com> writes:
import std.conv : to;

struct Matrix(T, size_t r, size_t c){

public:
  T[r*c] _data;

  Matrix opBinary(string op)(T scalar) if(op == "*"){
    string construct(){
      string result = "[";
      for(size_t i = 0; i < r * c; i++)
	result ~= "_data["~to!string(i)~"] * scalar, ";
      return result ~= "]";
    }
    return Matrix(mixin(construct()));
  }

  Matrix opBinary(string op)(ref const(Matrix) m)
    const if(op == "+" || op == "-"){
    string construct(){
      string result = "[";
      for(size_t i = 0; i < r * c; i++)
	result ~= "_data["~to!string(i)~"]"~op~"m._data["~to!string(i)~"], ";
      return result ~= "]";
    }
    return Matrix(mixin(construct()));
  }
}

struct A(T){

public:
  Matrix!(T, 3, 1) _a;
  alias _a this;

  this(T a, T b, T c){
    this._data[0] = a;
    this._data[1] = b;
    this._data[2] = c;
  }
}


void main(){

  auto a = A!double(3, 3, 3);

  auto r1 = a * 3.0;  // ok
  auto r2 = a + a;   // ok
  auto r3 = a + (a * 3.0);  // Error: incompatible types for ((a) +
(a._a.opBinary(3.0e+0))): 'A!(double)' and 'Matrix!(double,3,1)'
}


Why does the last expression fail? and how do I fix it?
Apr 05 2011
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 05 Apr 2011 13:23:04 -0400, Caligo <iteronvexor gmail.com> wrote:

 Why does the last expression fail? and how do I fix it?

Because alias this is not very well implemented yet (I've run into similar issues), and you fix it by creating a bug report or voting for an already existing one. Sorry. -Steve
Apr 05 2011
parent simendsjo <simen.endsjo pandavre.com> writes:
On 06.04.2011 02:15, Steven Schveighoffer wrote:
 On Tue, 05 Apr 2011 19:37:15 -0400, Caligo <iteronvexor gmail.com> wrote:

 It's just frustrating, that's all. Writing thousands of lines of code
 and having everything stop because of a compiler bug is just
 frustrating.

I completely understand. It's why I have to periodically stop using D. Dcollections sat idle for over a year while I waited for a compiler bug to be fixed.
 I know progress is being made, and all that is appreciated. But, I
 don't remember ever hearing anything about D2 being in beta. If
 anything, I remember months ago where D2 was recommended for new
 projects. So, now I'm not sure what I'm supposed to do. Start all
 over again from scratch? I really like my design, so I guess I'll
 have to wait till it gets fixed.

Sorry you got that impression. The fact is, as long as you are using the non-broken features, D2 is pretty useful, even downright awesome :) The issue is, if you hit one of those broken ones. Unfortunately, the release of TDPL didn't make all those features magically appear fully implemented. So since TDPL is promoted as the offical language spec, D2 suddenly jumped way back in the release cycle, since many of its unimplemented/not-fully-implemented features became "official". I'd highly recommend *NOT* to use D2 for new projects unless you are willing to redesign your code to work around those issues, or wait for them to be fixed. I truly wish this wasn't the case, but I don't see how anyone can confidently recommend D2 for professional or non-toy projects. This may sound like an anti-endorsement, but I assure you it is not. I think D2 is going to be absolutely killer when it's finished. I just would not use it for professional development *right now*, where deadlines and budgets are under consideration. If you can afford to put it down when it breaks and wait for a fix, then I think it will be worth the wait. -Steve

Both the d1 and d2 homepage states the following: There are two versions of the language: 1. D version 1 which is in maintenance mode. 2. D version 2 which is recommended for new projects. Should it mention that d2 is beta and phobos alpha? Or are you alone in thinking that?
Apr 06 2011
prev sibling next sibling parent Caligo <iteronvexor gmail.com> writes:
On Tue, Apr 5, 2011 at 12:32 PM, Steven Schveighoffer
<schveiguy yahoo.com> wrote:
 On Tue, 05 Apr 2011 13:23:04 -0400, Caligo <iteronvexor gmail.com> wrote:

 Why does the last expression fail? and how do I fix it?

Because alias this is not very well implemented yet (I've run into similar issues), and you fix it by creating a bug report or voting for an already existing one. Sorry. -Steve

*sigh*
Apr 05 2011
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 05 Apr 2011 14:08:42 -0400, Caligo <iteronvexor gmail.com> wrote:

 On Tue, Apr 5, 2011 at 12:32 PM, Steven Schveighoffer
 <schveiguy yahoo.com> wrote:
 On Tue, 05 Apr 2011 13:23:04 -0400, Caligo <iteronvexor gmail.com>  
 wrote:

 Why does the last expression fail? and how do I fix it?

Because alias this is not very well implemented yet (I've run into similar issues), and you fix it by creating a bug report or voting for an already existing one. Sorry. -Steve

*sigh*

Yeah, I know. I'd stay away from alias this for now if you don't want to be disappointed :( -Steve
Apr 05 2011
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
What's strange is that

auto r3 = r1 + r2;

works. Bug indeed...
Apr 05 2011
prev sibling next sibling parent Caligo <iteronvexor gmail.com> writes:
I searched the bugzilla and there are 'alias this' related bugs.  Some
of them are 2 years old and have not been fixed.

I've heard bugs get fixed rather quickly if something is posted on
reddit about them.
Apr 05 2011
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 05 Apr 2011 15:48:36 -0400, Caligo <iteronvexor gmail.com> wrote:

 I searched the bugzilla and there are 'alias this' related bugs.  Some
 of them are 2 years old and have not been fixed.

There are many bugs in that category. inout I think is a prime example. I don't really know what to say to appease your expectations, except to have patience or try learning the comipler code. If I had time and was compiler-savvy I might fix some bugs, but I don't and I'm not. Walter and Don seem to do a lot of good bug fixes, and usually these are critical issues. I think it won't be long before Walter or Don can start working on half-implemented features. I know of no timeline though.
 I've heard bugs get fixed rather quickly if something is posted on
 reddit about them.

I wouldn't push this avenue too much, if it is true, it's likely to become not true quite quickly if abused. I think it's more that bugs posted on reddit from people outside the D community look like outward-facing warts, and Walter and Andrei have a compulsive urge to make sure those are covered up quickly. I personally don't see why it's important, as long as progress is being made on *something*. Clearly the most visible wart was lack of 64-bit support, and that is almost resolved. But progress *is* being made. I think that's what's important right now. D2 is still very much beta, and Phobos 2 is very much alpha. -Steve
Apr 05 2011
prev sibling next sibling parent Caligo <iteronvexor gmail.com> writes:
It's just frustrating, that's all.  Writing thousands of lines of code
and having everything stop because of a compiler bug is just
frustrating.

I know progress is being made, and all that is appreciated.  But, I
don't remember ever hearing anything about D2 being in beta.  If
anything, I remember months ago where D2 was recommended for new
projects.  So, now I'm not sure what I'm supposed to do.  Start all
over again from scratch?  I really like my design, so I guess I'll
have to wait till it gets fixed.
Apr 05 2011
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 05 Apr 2011 19:37:15 -0400, Caligo <iteronvexor gmail.com> wrote:

 It's just frustrating, that's all.  Writing thousands of lines of code
 and having everything stop because of a compiler bug is just
 frustrating.

I completely understand. It's why I have to periodically stop using D. Dcollections sat idle for over a year while I waited for a compiler bug to be fixed.
 I know progress is being made, and all that is appreciated.  But, I
 don't remember ever hearing anything about D2 being in beta.  If
 anything, I remember months ago where D2 was recommended for new
 projects.  So, now I'm not sure what I'm supposed to do.  Start all
 over again from scratch?  I really like my design, so I guess I'll
 have to wait till it gets fixed.

Sorry you got that impression. The fact is, as long as you are using the non-broken features, D2 is pretty useful, even downright awesome :) The issue is, if you hit one of those broken ones. Unfortunately, the release of TDPL didn't make all those features magically appear fully implemented. So since TDPL is promoted as the offical language spec, D2 suddenly jumped way back in the release cycle, since many of its unimplemented/not-fully-implemented features became "official". I'd highly recommend *NOT* to use D2 for new projects unless you are willing to redesign your code to work around those issues, or wait for them to be fixed. I truly wish this wasn't the case, but I don't see how anyone can confidently recommend D2 for professional or non-toy projects. This may sound like an anti-endorsement, but I assure you it is not. I think D2 is going to be absolutely killer when it's finished. I just would not use it for professional development *right now*, where deadlines and budgets are under consideration. If you can afford to put it down when it breaks and wait for a fix, then I think it will be worth the wait. -Steve
Apr 05 2011
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
 On Tue, 05 Apr 2011 19:37:15 -0400, Caligo <iteronvexor gmail.com> wrote:
 It's just frustrating, that's all.  Writing thousands of lines of code
 and having everything stop because of a compiler bug is just
 frustrating.

I completely understand. It's why I have to periodically stop using D. Dcollections sat idle for over a year while I waited for a compiler bug to be fixed.
 I know progress is being made, and all that is appreciated.  But, I
 don't remember ever hearing anything about D2 being in beta.  If
 anything, I remember months ago where D2 was recommended for new
 projects.  So, now I'm not sure what I'm supposed to do.  Start all
 over again from scratch?  I really like my design, so I guess I'll
 have to wait till it gets fixed.

Sorry you got that impression. The fact is, as long as you are using the non-broken features, D2 is pretty useful, even downright awesome :) The issue is, if you hit one of those broken ones. Unfortunately, the release of TDPL didn't make all those features magically appear fully implemented. So since TDPL is promoted as the offical language spec, D2 suddenly jumped way back in the release cycle, since many of its unimplemented/not-fully-implemented features became "official". I'd highly recommend *NOT* to use D2 for new projects unless you are willing to redesign your code to work around those issues, or wait for them to be fixed. I truly wish this wasn't the case, but I don't see how anyone can confidently recommend D2 for professional or non-toy projects. This may sound like an anti-endorsement, but I assure you it is not. I think D2 is going to be absolutely killer when it's finished. I just would not use it for professional development *right now*, where deadlines and budgets are under consideration. If you can afford to put it down when it breaks and wait for a fix, then I think it will be worth the wait.

IIRC, Adam Ruppe uses D2 for professional development, and he discusses it from time to time on the main d newsgroup, but he specifically avoids some of the newer features. He rarely runs into problems with compiler. On the other hand, folks who consistently try and use the newer features in their code - especially when they try and mix them - run into problems all too frequently. I ran into a number of major issues while creating std.datetime. A number of them have been fixed now. Others remain unfixed and still affect affect std.datetime to some degree (e.g. it's impossible to create an immutable SysTime). But std.datetime uses some of the newer features quite heavily (though alias this isn't one of them). So, if you restrict what you do with D2 to an older subset of the language, you're likely to be fine. But if you try and use a lot of the newer features, you _will_ run into bugs. And alias this is definitely one of the areas with problems. Personally, I only use D2 for my personal stuff, but as much as I'd like to use it at work, I wouldn't even attempt to yet. The language is stabilizing, and the compiler and libraries are definitely improving, but if you expect rock-solid stability, you're going to be dissapointed. We're getting there, but we're not there yet. - Jonathan M Davis
Apr 05 2011
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 06 Apr 2011 12:32:37 -0400, simendsjo <simen.endsjo pandavre.com>  
wrote:

 Both the d1 and d2 homepage states the following:

 There are two versions of the language:
    1. D version 1 which is in maintenance mode.
    2. D version 2 which is recommended for new projects.

 Should it mention that d2 is beta and phobos alpha? Or are you alone in  
 thinking that?

I would recommend that it said this. Maybe I'm alone, and everyone else has no issues when they use D2. It's not up to me what to say on digitalmars, I am not in charge of that page. BTW, if it's a choice between D1/phobos and D2/phobos, I highly recommend D2/phobos. D1 phobos is woefully inadequate for any real projects (when I first learned D it was for a networking project at work, and I tried D1/phobos for about a week before looking for something better), I recommend D1/tango if you want to use D1. -Steve
Apr 07 2011