-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global using at declaration site. #35
Comments
That's an interesting idea! |
I had this same idea before. I wonder if this should be implemented as a first step to solve #10. The second step would then be to automatically move function declarations in enums to such static extension classes, and add the On its own, I wonder if its worth it given that we have import.hx and can just add |
|
Also, on second thought, I would like this for abstracts too as it allows dispatching on type parameters. Here's a poor example that hopefully still gets the point across: //Array.hx
@:coreType class Array<T> using ArrayTools { /* all methods except sort */ }
//ArrayTools.hx
class ArrayTools {
static public function sort<T>(a:Array<T>, compare:T->T->Int):Void;
}
class NumericArrayTools {
static public function sort<T:Float>(a:Array<T>):Void;
static public function sum<T:Float>(a:Array<T>):T;
}
class DateArrayTools {
static public function sort(a:Array<Date>):Void;
}
class ComparableArrayTools {
static public function sort<T:{ function compare(that:T):Int; }>(a:Array<T>):Void;
} |
It gives a nice method for adding "mixins" to your classes. Multiple classes can declare |
@back2dos are you going to convert this idea to a proposal? |
Well, if @ncannasse could confirm that he'll at least genuinely consider it, I can do that ^^ |
This needs a proper proposal. I can't speak for Nicolas, but I for one would genuinely consider it. |
Whoa, I thought this had been already implemented, but was just closed and forgotten... Is this going to become a proposal? |
oh sorry, I've overlooked HaxeFoundation/haxe#7462 |
Does not seem to works with abstract =/. I have Vec4 has no field add. class Vec4Tool {
public static inline function add(out: Vec4, v0: Vec4, v1: Vec4) : Vec4 {
out[0] = v0[0] + v1[0];
out[1] = v0[1] + v1[1];
out[2] = v0[2] + v1[2];
out[3] = v0[3] + v1[3];
return out;
}
}
@:using(Vec4.Vec4Tool)
@:forward abstract Vec4(Float32Array) from Float32Array to Float32Array {
public function new() {
this = new Float32Array([ 0.0, 0.0, 0.0, 1.0 ]);
}
@:arrayAccess
public inline function getValue(index: Int) {
return this[index];
}
@:arrayAccess
public inline function setValue(index: Int, value: Float) {
return this[index] = value;
}
} |
You should file a bug report, specifying which Haxe version you're using. |
The idea would is to allow
using
clauses onenum
,interface
and perhaps alsoclass
(although I don't see the use case there).This would globally apply the static extension, but only to the type being declared. It would solve #10 - albeit in a slightly awkward way.
On interfaces it could also do some good:
The text was updated successfully, but these errors were encountered: