林在SML使插入排序的代碼,這是SMLNJ插入排序操作和操作數不同意錯誤
fun compare(x:real, y:real, F) = F(x, y);
fun isEqual(x:real, y:real) = ((x <= y) andalso (x >= y));
fun rinsert(x: real, [], F) = [x]
|rinsert(x, (y::ys), F) =
if isEqual(x, y) then rinsert (x, ys, F)
else if compare(x, y, F) then x::y::ys
else y::(rinsert (x, ys, F));
fun rinsort([], F) = []
|rinsort(x::xs, F) = rinsert(x, (rinsort(xs, F), F));
但是,在運行它,我得到這個錯誤
val isEqual = fn : real * real -> bool
val rinsert = fn : real * real list * (real * real -> bool) -> real list
stdIn:12.27-12.58 Error: operator and operand don't agree [tycon mismatch]
operator domain: real * real list * (real * real -> bool)
operand: 'Z * ('Y list * 'X)
in expression:
rinsert (x,(rinsort (<exp>,<exp>),F))
我明白rinsort不正確地調用rinsert,但我不知道如何解決它。
'rinsert'需要多少個參數?你打了幾個電話? – melpomene
rinsert需要三個參數,一個實數,一個列表和一個運算符(如op <)。它應該只是叫三個 – small502
我不明白你的意思是「*它只應該叫三*」。看代碼。計算參數。那裏有多少? – melpomene