0
重複值,我想,如果我在列表查找列表
let rec repeats L =
match L with
| [] -> false
| x::xs when x = xs.Head -> true
| x::xs -> repeats xs;;
repeats [1;2;3;4;5]
找到一個重複的值應該返回false返回true。但我得到這個錯誤:
System.InvalidOperationException: The input list was empty.
at Microsoft.FSharp.Collections.FSharpList`1.get_Head()
at FSI_0003.repeats[a](FSharpList`1 L)
at <StartupCode$FSI_0004>[email protected]()
at [email protected]()
Stopped due to error
我該怎麼辦才能解決這個錯誤?
編輯我的問題,以匹配改變的代碼。但我仍然得到一個錯誤 – jth41
刪除第二個大小寫塊(x = xs.Head - > true'時的'| x :: xs) – khyperia
Bingo。很好的工作現在很thx – jth41