I can't figure out how to implement the Zip function in F#. Can anyone tell me what I am doing wrong? Here is what I have typed into fsi.exe
:
> 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"))]
In your example ["a","b","c","d"]
is a list that contains one element which is 4-dimensional tuple. That is why you are getting unexpected results from zip.
Just use ;
as elements delimiter instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With