Skip to content
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

Feature Request : haxe.ds.Vector.sort #3388

Open
delahee opened this issue Sep 23, 2014 · 11 comments
Open

Feature Request : haxe.ds.Vector.sort #3388

delahee opened this issue Sep 23, 2014 · 11 comments

Comments

@delahee
Copy link
Contributor

delahee commented Sep 23, 2014

Hi

Would be cool to have a cross platform to a native sort ( just like Array.sort )

For example for cross platform particles and such.

++

@Simn
Copy link
Member

Simn commented Sep 23, 2014

I don't know how practical that would be. You would have to pass a comparison function which already is a problem on some targets. We could do better with static extensions that restrict to specific types (e.g. Vector<Int>), but these always have to be brought into context.

It would be nice if we could define multiple selective abstract functions with the same name. This would allow us to define sort(this:Vector<Int>) and sort(this:Vector<String>) directly on Vector itself.

I'll have to think about this.

@nadako
Copy link
Member

nadako commented Sep 23, 2014

It would be nice if we could define multiple selective abstract functions with the same name. This would allow us to define sort(this:Vector) and sort(this:Vector) directly on Vector itself.

That is also what I was talking about WRT Map.iterator - we could probably implement selective iterator function that returns concrete class to make @SmerkyG happy 😉

@Simn
Copy link
Member

Simn commented Sep 23, 2014

@waneck: Shouldn't this work on Java target?

abstract A<T>(Array<T>) {
    public inline function new(a:Array<T>) {
        this = a;
    }

    @:overload static inline public function sum(a:A<Int>) {
        trace("sum of ints");
    }

    @:overload static inline public function sum(a:A<String>) {
        trace("sum of strings");
    }
}

class Main {
    static function main() {
        var a = new A(["1", "2", "3"]);
        a.sum(); // A<String> should be A<Int>
    }
}

@waneck
Copy link
Member

waneck commented Oct 8, 2014

Type parameters evaluation are delayed IIRC. Why is that?
On Sep 23, 2014 7:42 AM, "Simon Krajewski" notifications@github.com wrote:

@waneck: Shouldn't this work on Java target?

abstract A(Array) {
public inline function new(a:Array) {
this = a;
}

@:overload static inline public function sum(a:A<Int>) {
    trace("sum of ints");
}

@:overload static inline public function sum(a:A<String>) {
    trace("sum of strings");
}

}

class Main {
static function main() {
var a = new A(["1", "2", "3"]);
a.sum(); // A should be A
}
}


Reply to this email directly or view it on GitHub.

@ncannasse
Copy link
Member

@waneck most likely because of constraints

@waneck
Copy link
Member

waneck commented Oct 8, 2014

I see. The problem is most probably there - IIRC a type parameter check failure bypasses the overload selection and just shows an error.

@Simn Simn assigned Simn and unassigned waneck Oct 8, 2014
@Simn
Copy link
Member

Simn commented Oct 8, 2014

Hold on, this is at least partially my fault.

@Simn
Copy link
Member

Simn commented Oct 10, 2014

So, my example now works on Java and C#. I would like to suggest allowing this for abstracts on all targets with the requirement that the method be inline (and forcing the inline).

@SmerkyG
Copy link
Contributor

SmerkyG commented Oct 10, 2014

It would be great if this made it possible for Math.Max to properly deal with Ints instead of always forcing the return value to Float.

@waneck
Copy link
Member

waneck commented Oct 10, 2014

That would be an awesome addition, Simn!

@Simn
Copy link
Member

Simn commented Oct 10, 2014

I was trying to get it implemented, but there's too much going on with pf_overload for me to get it right.

@Simn Simn added this to the 3.3 milestone Dec 13, 2014
@Simn Simn modified the milestones: 3.3.0-rc1, 3.4 Feb 23, 2016
@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Design Apr 17, 2018
@Simn Simn removed their assignment Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants