Multiple constraints in generics

  • Thread starter Thread starter Hung Jung Lu
  • Start date Start date
H

Hung Jung Lu

Hi,

I just downloaded rotor and gyro and am playing a bit with generics. I
enclose a sample program. My question is, according to the language
spec (http://msdn.microsoft.com/vcsharp/team/language/default.aspx, C#
2.0 Specification), a syntax like:

public class MathEngine<T> where T: IHasX, IHasY {

}

should be valid. Yet, the rotor+gyro compiler complains. I have
attempted also

public class MathEngine<T> where T: IHasX, T: IHasY {

}

but it seems that it only picks up the last part, namely, only IHasY.

I know rotor+gyro are kind of experimental, but still, I'd like to
make sure I am not missing out obvious explanations. Are these
problems just bugs?

Regards,

Hung Jung


using System;

public interface IHasX {
int x {get;set;}
}

public interface IHasY {
int y {get;set;}
}

public class MathEngine<T> where T: IHasX, IHasY {
public void incX(T me) {
int x;
x = me.x;
x += 1;
me.x = x;
}
public void incY(T me) {
int y;
y = me.y;
y += 1;
me.y = y;
}
}

public class A: IHasX, IHasY {

int _x;
int _y;

public MathEngine<A> math;

public A() {
_x = 2;
_y = 3;
math = new MathEngine<A>();
}

public int x {
get {return _x;}
set {_x = value;}
}

public int y {
get {return _y;}
set {_y = value;}
}

public void calc() {
math.incX(this);
}

}

class MainApp {
public static void Main() {
A a;
a = new A();
a.calc();
Console.WriteLine("Values = {0}", a.x);
}
}
 
Hung,

Well, you kind of explained it yourself. The Rotor/Gyro implementations
were created before the designs were confirmed for the next version of the
framework. Constraints might not have been in the original design for the
CLR when they did the Rotor/Gyro project.

I wouldn't expect the new version of the CLR/Framework to work with the
current version of Rotor/Gyro.

Hope this helps.
 
Nicholas Paldino said:
Well, you kind of explained it yourself. The Rotor/Gyro implementations
were created before the designs were confirmed for the next version of the
framework. Constraints might not have been in the original design for the
CLR when they did the Rotor/Gyro project.

I wouldn't expect the new version of the CLR/Framework to work with the
current version of Rotor/Gyro.

Thanks. I also got confirmation from someone else on the
one-constraint limitation for the Gyro generics. It is actually also
mentioned in gyro.html in the unpacked distribution files.

regards,

Hung Jung
 
Back
Top