當我嘗試編譯我的ML程序時,出現錯誤:「操作員和操作數不同意」。錯誤SML NJ-操作符和操作數不同意
candidates.sml:78.8-78.40 Error: operator and operand don't agree [tycon mismatch]
operator domain: int * (int * 'Z * 'Y) list
operand: int * (int * real) list
in expression:
tr (n,candidates)
我明白錯誤,但我找不到解決方案。 在那裏我得到錯誤代碼的部分是:
fun agonas fileName =
let
fun tr(n,[])=[]
| tr(n,((a,b,c)::d))=((n-a+1),b,c)::(tr(n,d))
val (n,l,candidates) = parse fileName
val cand = tr(n,candidates)
in
my_solution(l,cand)
end;
,那裏的考生與下面的部分相關:
fun parse file =
let
(* a function to read an integer from an input stream *)
fun next_int input =
Option.valOf (TextIO.scanStream (Int.scan StringCvt.DEC) input)
(* a function to read a real that spans till the end of line *)
fun next_real input =
Option.valOf (TextIO.inputLine input)
(* open input file and read the two integers in the first line *)
val stream = TextIO.openIn file
val n = next_int stream
val l = next_int stream
val _ = TextIO.inputLine stream
(* a function to read the pair of integer & real in subsequent lines *)
fun scanner 0 acc = acc
| scanner i acc =
let
val d = next_int stream
val (SOME v) = Real.fromString (next_real stream)
in
scanner (i - 1) ((d, v) :: acc)
end
in
(n, l, rev(scanner n []))
end;
fun my_solution (n , l ,candidates) = [2 ,3 ,5 ,4 ,6]
fun agonas fileName = my_solution (parse fileName)
我將不勝感激,如果你能找到mistake.Thanks提前。
對不起,功能TR是同功能trans.I現在編輯。你可以看到錯誤?感謝您的時間。 – user3754251
那麼,這個錯誤就是我已經描述過的:你的''parse'''''scanner'函數和你的'tr'函數不同意'candidates'列表的結構。很難說如何解決它而不知道這段代碼試圖達到什麼目的。但對於初學者來說,你可以嘗試在函數tr中刪除元組中的'c'組件。 –