3
我無法弄清楚如何在F#中實現Zip函數。誰能告訴我我做錯了什麼?以下是我已經輸入到fsi.exe
:F#zip實現
> let rec zip xs ys =
- match xs with
- | [] -> []
- | head :: tail -> (match ys with
- | [] -> []
- | headY :: tailY -> (head, headY) :: zip tail tailY);;
val zip : xs:'a list -> ys:'b list -> ('a * 'b) list
> zip [1;2;3;4] ["a","b","c","d"];;
val it : (int * (string * string * string * string)) list =
[(1, ("a", "b", "c", "d"))]
備選: 讓REC ZIP2 XS YS = 比賽XS,與 YS | XH :: XT,YH :: YT - >(XH,YH)::(zip2 xt yt) | _,_ - > [] https://dotnetfiddle.net/9TkL3k –