我想做一个叫做 zip 的函数,所以:
zip [1;2;3;4] [5;6;7;8] 会产生: [1;5;2;6;3;7;4;8]
但我收到一个错误:line#4 h2::t2 make error syntax error : pattern expected
什么是正确的语法?
let rec zip lst1 lst2 =
match lst1 lst2 with
| [] [] -> []
| h1::t1 h2::t2 -> h1 h2::zip t1 t2
|_ _ -> failwith "The lists seems to have different lengths";;