我试图通过采用备用元素将 F# 列表分成两部分。这是我的尝试:
let split l =
let rec loop l isEven result1 result2 =
match l with
| [] -> result1 result2
| [head::tail] when isEven -> loop tail (not isEven) head::result1 result2
| [head::tail] -> loop tail (not isEven) result1 head::result2
loop l false [] []
这给了我一个错误:
Program.fs(5,39): error FS0001: Type mismatch. Expecting a
'a
but given a
'b -> 'a list
The resulting type would be infinite when unifying ''a' and ''b -> 'a list'
我不明白它怎么可能是无限的,我不明白为什么它认为我给它一个从 'b 到 'a 列表的函数。有人可以告诉我哪里出错了吗?