0

リストに繰り返し値が見つかったら 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]   

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

エラーを修正するにはどうすればよいですか?

4

1 に答える 1

2

問題はそれです

x::xs = 5::[]

最後の場合

あなたはそれをに変更したい

|x::xs::xss when x=xs -> true
于 2013-10-01T03:35:20.990 に答える