如果我在列表中找到重复值
,我想返回truelet 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。但是我得到了这个错误:
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
我该怎么做才能解决错误?
答案 0 :(得分:2)
问题在于
x::xs = 5::[]
在最后一个案例中
您想将其更改为
|x::xs::xss when x=xs -> true