我試圖建立列表最小值出現的索引列表。在OCaml中輸入錯誤
let rec max_index l =
let rec helper inList min builtList index =
match inList with
| [] -> builtList
| x :: xs ->
if (x < min) then
helper xs x index :: builtList index + 1 //line 63
else
helper xs min builtList index + 1
in helper l 100000 [] 0;;
它給我下面的錯誤線路63
Error: This expression has type 'a list -> 'a list
but an expression was expected of type 'a
The type variable 'a occurs inside 'a list -> 'a list
預計類型的「A的表達?我不確定它爲什麼這麼說。我的猜測是它有事情做與index::builtList
我其實誤以爲這兩行。我已經更新了它。同樣的錯誤,雖然 – user2079802
我希望你能幫助的另一件事..你知道如何使它更安全/多態嗎?現在,當我運行它時,我得到'這個表達式的類型爲float,但是表達式期望爲int類型 - 行62 – user2079802
@ user2079802你得到那個if(x
mydogisbox