我有一個拉姆達加入C#,看起來像這樣:如何在F#中進行此加入?
int[] arrX = { 1, 2, 3 };
int[] arrY = { 3, 4, 5 };
var res = arrX.Join(arrY, x => x, y => y, (x, y) => x);
執行RES後包含3這是兩個陣列常見。
我想在F#完全相同的拉姆達加入,並嘗試:
let arrX = [| 1; 2; 3 |]
let arrY = [| 3; 4; 5 |]
let res = arrX.Join(fun arrY, fun x -> x, fun y -> y, fun (x, y) -> x)
但是編譯器說:
意外的象徵 '' 在lambda表達式。預期' - >'或其他令牌。
錯誤是第一個參數arrY後的逗號。
你能告訴我如何讓它工作(作爲lambda表達式)嗎?
在你的身上ular實例,'System.Linq.Enumerable.Intersect(arrX,arrY)'不需要函數委託。 – kaefer