I tried implementing Quicksort based on a Wikipedia example:
(Array:[]t where t:type).Partition(Low:int, High:int):int=
if(Pivot := Array[Floor[(High*1.0-Low*1.0)/2.0]+Low]):
var Left : int = Low-1
var Right : int = High+1
loop:
loop:
set Left += 1
if(Array[Left] >= Pivot). break
loop:
set Right -= 1
if(Array[Right] <= Pivot). break
if(Left>=Right). return Right
Tmp := Left
set Left = Right
set Right = Left
return 0
(Array:[]t where t:type).Sort(Low:int, High:int):[]t=
if(Low >= 0 and High >= 0 and Low < High):
P := Array.Partition(Low, High)
Array.Sort(Array,Low,P)
Array.Sort(Array,P+1,High)
return Array
but it isn’t compiling because it doesn’t know which overload of +, -, > and < to use.
I assume this should be possible in the future as it doesn’t seem that difficult for the compiler to figure out, but it currently seems impossible?
Or does anyone know if there’s a way to work around this issue?
Edit: I realize I really screwed up the algorithm and the code is completely broken, I really should have made a non-polymorphic version and tested it before posting But anyways the main issue is still whether there’s a way to get Verse to use the correct overloads currently
Edit: Here’s a working non-polymorphic version:
int_array_ref := class<unique>:
var Data : []int = array{}
(Array:int_array_ref).Partition(Low:int, High:int):int=
if(Pivot := Array.Data[Floor[(High*1.0-Low*1.0)/2.0]+Low]):
var Left : int = Low-1
var Right : int = High+1
loop:
loop:
set Left += 1
if(Array.Data[Left]>=Pivot). break
loop:
set Right -= 1
if(Array.Data[Right]<=Pivot). break
if(Left >= Right). return Right
if(Tmp := Array.Data[Left]):
if(set Array.Data[Left] = Array.Data[Right]){}
if(set Array.Data[Right] = Tmp){}
return 0
(Array:int_array_ref).Sort(Low:int, High:int):void=
if(Low >= 0 and High >= 0 and Low < High):
P := Array.Partition(Low, High)
Array.Sort(Low,P)
Array.Sort(P+1,High)