Haxe List Sort

  •    var persons: List<Person> = readPersonsFile("persons.txt");
    ListSort.sort(persons, function(personA, personB): Int
        return Person.compare(personA , personB);

    In the code above I just want to sort the list of people objects. But it keeps giving me this error:

    src/Main.hx:18: characters 2-15 : Constraint check failure for sort.T src/Main.hx:18: characters 2-15 : List should be { prev : List, next : List } src/Main.hx:18: characters 2-15 : List has no field next

    Any help would be appreciated, thanks.

  • Which line is Main.hx:18?

    You can change the function parameters like this:
    function( personA:Person, personB:Person ) : Int

    Take a look at 43. line.
    Error is about this: sort<T:{prev:T,next:T}>

    If you have a single linked list (just has property of next element) you must use:
    ListSort.sortSingleLinked(); // sortSingleLinked<T:{next:T}>(list:T, cmp : T -> T -> Int) : T

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.