Closed MetaChrome closed 10 years ago
Operator overloading is only supported for abstract types. We do not plan to support it for classes or interfaces.
Can you specify the logical error with regards to this?
package ugh.shared.geom;
import ugh.shared.dev.pre.Gen;
import ugh.shared.dev.pre.Gen_s;
class Rect_prism_gen_s extends Gen_s {
public var ntu:String;
public var t:String;
public function new(
t:String,
nt:String,
ntu:String,
?ext:String
) {
super(t,ext);
this.nt=nt;
this.ntu=ntu;
}
}
class Rect_prism_gen extends Gen<Rect_prism_gen_s> {
override public function init(?v:Dynamic):Void {
super.init(v);
var types:Array<Rect_prism_gen_s>=[
new Rect_prism_gen_s("ugh.shared.geom.Rpf","Float","ugh.shared.Fu"),
new Rect_prism_gen_s("ugh.shared.geom.Rpfp","ugh.shared.Fp","ugh.shared.Fpu"),
new Rect_prism_gen_s("ugh.shared.geom.Rpi","Int","ugh.shared.Iu",false)
];
types_gen(types);
}
override public function content(s:Rect_prism_gen_s):String {
var r:String='';
return r;
}
}
I don't understand if fixing generics to their logical conclusion by fixing literally 2-3 bugs is not a monumental task considering the scope of haxe, you would willingly facilitate the above in user code (as further evidenced by the existence and use of caxe and my own haxe preprocessor)
If you understand how to fix generics can you please, please, please at least an answer to my queries on the matter of @:generic and specify why this particular issue is not correct as it is a logical extension?
I'm not trying to discount your efforts on other parts of haxe I just truly don't understand why generics cannot be fixed in a reasonable amount of time. If specify a goal like: we would like to have a completely correct and convenient @:generic implementation after completing particular higher prioritized goals and within a target x amount of time, I can proceed in a reasonable way.
I can't understand what's the actual problem and posting walls of random code is not making things more clear. You talk about some bugs in @:generics, however you are posting code that tries to use operator overloading and implicit casting on interfaces, which are only supported by abstracts. Second code example doesn't illustrate anything, being torn off from its context.
Please, provide a minimal and reproducible code example that shows the problem, without any dependencies, imports or extra fields that doesn't relate to the problem. And create one issue per each problem you find. This way developers can understand you.
Thanks!
I would be happy to work on this if it evaluated as being reasonable/logically correct.
Here is the requested example with regards that fails in multiple ways with the current implementation:
package;
abstract Number(Int) {
inline function new(x:Int) this = x;
public inline function raw() return this;
@:to public inline function toi():Int return this-1;
@:from public static inline function fromi(v:Int):Number return new Number(v+1);
@:op(A+B) public inline static function add(v:Number,v2:Number):Number {
return new Number(v.raw()+v2.raw()+1);
}
}
class U<T> {
public function new() {
}
public function foo(v:T):T {
return v+v;
}
}
class Test {
public static function main() {
new Test();
}
public function new() {
var v:Number=1;
var u:U<Number>=new U<Number>();
trace(u.foo(v));
}
}
With regards to declaring overloaded operators as member functions, c++ currently does so. c++ instructions to declare binary operators that treat both operands equally (and others) as non-member, may be one of optimization with regards to generation as a static, but this can likely be overcome with a specification in the interface.
So, as far as I understood, one of the problems you are facing is that there's no way to express a type constraint for a type that supports operators, i.e.:
class A<T:{@:op(A+B) function add(a:T, b:T):T}>
{
function foo(v:T):T return v + v;
}
That is one minimal and particular case that is worth a separate issue and discussion.
Yes.
That is this issue though. The discussion with regards to generic is specifying:
In addition, because of the nature of constraints, interface or not, I just skipped to presuming that the overloaded methods would be member functions. Hence said original post.
Containers manipulating said interfaces: