如果我在列表中找到重复值,我想返回 true
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]
应该返回假。但我得到这个错误:
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>.$FSI_0004.main@()
at main@dm()
Stopped due to error
我应该怎么做才能修复错误?